Path: blob/master/src/infrastructure/daemon/workers/action/PhabricatorTriggerAction.php
12242 views
<?php12/**3* A trigger action reacts to a scheduled event.4*5* Almost all events should use a @{class:PhabricatorScheduleTaskTriggerAction}.6* Avoid introducing new actions without strong justification. See that class7* for discussion of concerns.8*/9abstract class PhabricatorTriggerAction extends Phobject {1011private $properties;1213public function __construct(array $properties) {14$this->validateProperties($properties);15$this->properties = $properties;16}1718public function getProperties() {19return $this->properties;20}2122public function getProperty($key, $default = null) {23return idx($this->properties, $key, $default);24}252627/**28* Validate action configuration.29*30* @param map<string, wild> Map of action properties.31* @return void32*/33abstract public function validateProperties(array $properties);343536/**37* Execute this action.38*39* IMPORTANT: Trigger actions must execute quickly!40*41* In most cases, trigger actions should queue a worker task and then exit.42* The actual trigger execution occurs in a locked section in the trigger43* daemon and blocks all other triggers. By queueing a task instead of44* performing processing directly, triggers can execute more involved actions45* without blocking other triggers.46*47* Almost all events should use @{class:PhabricatorScheduleTaskTriggerAction}48* to do this, ensuring that they execute quickly.49*50* An action may trigger a long time after it is scheduled. For example,51* a meeting reminder may be scheduled at 9:45 AM, but the action may not52* execute until later (for example, because the server was down for53* maintenance). You can detect cases like this by comparing `$this_epoch`54* (which holds the time the event was scheduled to execute at) to55* `PhabricatorTime::getNow()` (which returns the current time). In the56* case of a meeting reminder, you may want to ignore the action if it57* executes too late to be useful (for example, after a meeting is over).58*59* Because actions should normally queue a task and there may be a second,60* arbitrarily long delay between trigger execution and task execution, it61* may be simplest to pass the trigger time to the task and then make the62* decision to discard the action there.63*64* @param int|null Last time the event occurred, or null if it has never65* triggered before.66* @param int The scheduled time for the current action. This may be67* significantly different from the current time.68* @return void69*/70abstract public function execute($last_epoch, $this_epoch);7172}737475