Path: blob/master/src/infrastructure/daemon/workers/clock/PhabricatorTriggerClock.php
12242 views
<?php12/**3* A trigger clock implements scheduling rules for an event.4*5* Two examples of triggered events are a subscription which bills on the 12th6* of every month, or a meeting reminder which sends an email 15 minutes before7* an event. A trigger clock contains the logic to figure out exactly when8* those times are.9*10* For example, it might schedule an event every hour, or every Thursday, or on11* the 15th of every month at 3PM, or only at a specific time.12*/13abstract class PhabricatorTriggerClock extends Phobject {1415private $properties;1617public function __construct(array $properties) {18$this->validateProperties($properties);19$this->properties = $properties;20}2122public function getProperties() {23return $this->properties;24}2526public function getProperty($key, $default = null) {27return idx($this->properties, $key, $default);28}293031/**32* Validate clock configuration.33*34* @param map<string, wild> Map of clock properties.35* @return void36*/37abstract public function validateProperties(array $properties);383940/**41* Get the next occurrence of this event.42*43* This method takes two parameters: the last time this event occurred (or44* null if it has never triggered before) and a flag distinguishing between45* a normal reschedule (after a successful trigger) or an update because of46* a trigger change.47*48* If this event does not occur again, return `null` to stop it from being49* rescheduled. For example, a meeting reminder may be sent only once before50* the meeting.51*52* If this event does occur again, return the epoch timestamp of the next53* occurrence.54*55* When performing routine reschedules, the event must move forward in time:56* any timestamp you return must be later than the last event. For instance,57* if this event triggers an invoice, the next invoice date must be after58* the previous invoice date. This prevents an event from looping more than59* once per second.60*61* In contrast, after an update (not a routine reschedule), the next event62* may be scheduled at any time. For example, if a meeting is moved from next63* week to 3 minutes from now, the clock may reschedule the notification to64* occur 12 minutes ago. This will cause it to execute immediately.65*66* @param int|null Last time the event occurred, or null if it has never67* triggered before.68* @param bool True if this is a reschedule after a successful trigger.69* @return int|null Next event, or null to decline to reschedule.70*/71abstract public function getNextEventEpoch($last_epoch, $is_reschedule);7273}747576