1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 08:52:39 +01:00

Add a "schedule task" trigger action

Summary: Ref T6881. Add a standard "just queue a task" trigger action; I expect almost all application code to use this.

Test Plan: Will test in Instances.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T6881

Differential Revision: https://secure.phabricator.com/D11429
This commit is contained in:
epriestley 2015-01-19 16:55:23 -08:00
parent 3860c56e85
commit 7cbbd7868f
3 changed files with 54 additions and 0 deletions

View file

@ -2362,6 +2362,7 @@ phutil_register_library_map(array(
'PhabricatorSSHWorkflow' => 'infrastructure/ssh/PhabricatorSSHWorkflow.php',
'PhabricatorSavedQuery' => 'applications/search/storage/PhabricatorSavedQuery.php',
'PhabricatorSavedQueryQuery' => 'applications/search/query/PhabricatorSavedQueryQuery.php',
'PhabricatorScheduleTaskTriggerAction' => 'infrastructure/daemon/workers/action/PhabricatorScheduleTaskTriggerAction.php',
'PhabricatorScopedEnv' => 'infrastructure/env/PhabricatorScopedEnv.php',
'PhabricatorSearchAbstractDocument' => 'applications/search/index/PhabricatorSearchAbstractDocument.php',
'PhabricatorSearchApplication' => 'applications/search/application/PhabricatorSearchApplication.php',
@ -5643,6 +5644,7 @@ phutil_register_library_map(array(
'PhabricatorPolicyInterface',
),
'PhabricatorSavedQueryQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhabricatorScheduleTaskTriggerAction' => 'PhabricatorTriggerAction',
'PhabricatorSearchApplication' => 'PhabricatorApplication',
'PhabricatorSearchApplicationSearchEngine' => 'PhabricatorApplicationSearchEngine',
'PhabricatorSearchAttachController' => 'PhabricatorSearchBaseController',

View file

@ -0,0 +1,45 @@
<?php
/**
* Trigger action which queues a task.
*
* Most triggers should take this action: triggers need to execute as quickly
* as possible, and should generally queue tasks instead of doing any real
* work.
*
* In some cases, triggers could execute more quickly by examining the
* scheduled action time and comparing it to the current time, then exiting
* early if the trigger is executing too far away from real time (for example,
* it might not make sense to send a meeting reminder after a meeting already
* happened).
*
* However, in most cases the task needs to have this logic anyway (because
* there may be another arbitrarily long delay between when this code executes
* and when the task executes), and the cost of queueing a task is very small,
* and situations where triggers are executing far away from real time should
* be rare (major downtime or serious problems with the pipeline).
*
* The properties of this action map to the parameters of
* @{method:PhabricatorWorker::scheduleTask}.
*/
final class PhabricatorScheduleTaskTriggerAction
extends PhabricatorTriggerAction {
public function validateProperties(array $properties) {
PhutilTypeSpec::checkMap(
$properties,
array(
'class' => 'string',
'data' => 'map<string, wild>',
'options' => 'map<string, wild>',
));
}
public function execute($last_epoch, $this_epoch) {
PhabricatorWorker::scheduleTask(
$this->getProperty('class'),
$this->getProperty('data'),
$this->getProperty('options'));
}
}

View file

@ -2,6 +2,10 @@
/**
* A trigger action reacts to a scheduled event.
*
* Almost all events should use a @{class:PhabricatorScheduleTaskTriggerAction}.
* Avoid introducing new actions without strong justification. See that class
* for discussion of concerns.
*/
abstract class PhabricatorTriggerAction extends Phobject {
@ -41,6 +45,9 @@ abstract class PhabricatorTriggerAction extends Phobject {
* performing processing directly, triggers can execute more involved actions
* without blocking other triggers.
*
* Almost all events should use @{class:PhabricatorScheduleTaskTriggerAction}
* to do this, ensuring that they execute quickly.
*
* An action may trigger a long time after it is scheduled. For example,
* a meeting reminder may be scheduled at 9:45 AM, but the action may not
* execute until later (for example, because the server was down for