Path: blob/master/src/infrastructure/daemon/workers/clock/PhabricatorDailyRoutineTriggerClock.php
12242 views
<?php12/**3* Triggers a daily routine, like server backups.4*5* This clock triggers events every 24 hours, using UTC. It does not use a6* locale, and is intended for technical processes like backing up a server7* every night.8*9* Because UTC does not have daylight savings, the local hour when this event10* occurs will change over the course of the year. For example, from the11* perspective of a user in California, it might run backups at 3AM in the12* winter and 2AM in the summer. This is desirable for maintenance processes,13* but problematic for some human processes. Use a different clock if you're14* triggering a human-oriented event.15*16* The clock uses the time of day of the `start` epoch to calculate the time17* of day of the next event, so you can change the time of day when the event18* occurs by adjusting the `start` time of day.19*/20final class PhabricatorDailyRoutineTriggerClock21extends PhabricatorTriggerClock {2223public function validateProperties(array $properties) {24PhutilTypeSpec::checkMap(25$properties,26array(27'start' => 'int',28));29}3031public function getNextEventEpoch($last_epoch, $is_reschedule) {32$start_epoch = $this->getProperty('start');33if (!$last_epoch) {34$last_epoch = $start_epoch;35}3637$start = new DateTime('@'.$start_epoch);38$last = new DateTime('@'.$last_epoch);3940// NOTE: We're choosing the date from the last event, but the time of day41// from the start event. This allows callers to change when the event42// occurs by updating the trigger's start parameter.43$ymd = $last->format('Y-m-d');44$hms = $start->format('G:i:s');4546$next = new DateTime("{$ymd} {$hms} UTC");4748// Add a day.49// NOTE: DateInterval doesn't exist until PHP 5.3.0, and we currently50// target PHP 5.2.3.51$next->modify('+1 day');5253return (int)$next->format('U');54}5556}575859