@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3/**
4 * A trigger action reacts to a scheduled event.
5 *
6 * Almost all events should use a @{class:PhabricatorScheduleTaskTriggerAction}.
7 * Avoid introducing new actions without strong justification. See that class
8 * for discussion of concerns.
9 */
10abstract class PhabricatorTriggerAction extends Phobject {
11
12 private $properties;
13
14 public function __construct(array $properties) {
15 $this->validateProperties($properties);
16 $this->properties = $properties;
17 }
18
19 public function getProperties() {
20 return $this->properties;
21 }
22
23 public function getProperty($key, $default = null) {
24 return idx($this->properties, $key, $default);
25 }
26
27
28 /**
29 * Validate action configuration.
30 *
31 * @param map<string, mixed> $properties Map of action properties.
32 * @return void
33 */
34 abstract public function validateProperties(array $properties);
35
36
37 /**
38 * Execute this action.
39 *
40 * IMPORTANT: Trigger actions must execute quickly!
41 *
42 * In most cases, trigger actions should queue a worker task and then exit.
43 * The actual trigger execution occurs in a locked section in the trigger
44 * daemon and blocks all other triggers. By queueing a task instead of
45 * performing processing directly, triggers can execute more involved actions
46 * without blocking other triggers.
47 *
48 * Almost all events should use @{class:PhabricatorScheduleTaskTriggerAction}
49 * to do this, ensuring that they execute quickly.
50 *
51 * An action may trigger a long time after it is scheduled. For example,
52 * a meeting reminder may be scheduled at 9:45 AM, but the action may not
53 * execute until later (for example, because the server was down for
54 * maintenance). You can detect cases like this by comparing `$this_epoch`
55 * (which holds the time the event was scheduled to execute at) to
56 * `PhabricatorTime::getNow()` (which returns the current time). In the
57 * case of a meeting reminder, you may want to ignore the action if it
58 * executes too late to be useful (for example, after a meeting is over).
59 *
60 * Because actions should normally queue a task and there may be a second,
61 * arbitrarily long delay between trigger execution and task execution, it
62 * may be simplest to pass the trigger time to the task and then make the
63 * decision to discard the action there.
64 *
65 * @param int|null $last_epoch Last time the event occurred, or null if it
66 * has never triggered before.
67 * @param int $this_epoch The scheduled time for the current action. This
68 * may be significantly different from the current time.
69 * @return void
70 */
71 abstract public function execute($last_epoch, $this_epoch);
72
73}