From 7cbbd7868f21ac7dac853eabca8d938df887e559 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 19 Jan 2015 16:55:23 -0800 Subject: [PATCH] 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 --- src/__phutil_library_map__.php | 2 + .../PhabricatorScheduleTaskTriggerAction.php | 45 +++++++++++++++++++ .../action/PhabricatorTriggerAction.php | 7 +++ 3 files changed, 54 insertions(+) create mode 100644 src/infrastructure/daemon/workers/action/PhabricatorScheduleTaskTriggerAction.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 780bf11799..076be4b597 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -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', diff --git a/src/infrastructure/daemon/workers/action/PhabricatorScheduleTaskTriggerAction.php b/src/infrastructure/daemon/workers/action/PhabricatorScheduleTaskTriggerAction.php new file mode 100644 index 0000000000..37742899a9 --- /dev/null +++ b/src/infrastructure/daemon/workers/action/PhabricatorScheduleTaskTriggerAction.php @@ -0,0 +1,45 @@ + 'string', + 'data' => 'map', + 'options' => 'map', + )); + } + + public function execute($last_epoch, $this_epoch) { + PhabricatorWorker::scheduleTask( + $this->getProperty('class'), + $this->getProperty('data'), + $this->getProperty('options')); + } + +} diff --git a/src/infrastructure/daemon/workers/action/PhabricatorTriggerAction.php b/src/infrastructure/daemon/workers/action/PhabricatorTriggerAction.php index a07aad7826..2390a284ba 100644 --- a/src/infrastructure/daemon/workers/action/PhabricatorTriggerAction.php +++ b/src/infrastructure/daemon/workers/action/PhabricatorTriggerAction.php @@ -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