From 02eca684ae8cc08a6302bc1173bcab2442a331e7 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 19 Jan 2015 16:56:03 -0800 Subject: [PATCH] Add a call to predict the next event for a trigger Summary: Ref T6881. This is useful to show a "Next backup: 2:30 AM" sort of thing without requring callers to know how triggers work internally. Test Plan: Showed that kind of thing in Instances. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T6881 Differential Revision: https://secure.phabricator.com/D11437 --- .../storage/PhabricatorWorkerTrigger.php | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/infrastructure/daemon/workers/storage/PhabricatorWorkerTrigger.php b/src/infrastructure/daemon/workers/storage/PhabricatorWorkerTrigger.php index 0fe4943237..abbe095670 100644 --- a/src/infrastructure/daemon/workers/storage/PhabricatorWorkerTrigger.php +++ b/src/infrastructure/daemon/workers/storage/PhabricatorWorkerTrigger.php @@ -130,6 +130,26 @@ final class PhabricatorWorkerTrigger } + /** + * Predict the epoch at which this trigger will next fire. + * + * @return int|null Epoch when the event will next fire, or `null` if it is + * not planned to trigger. + */ + public function getNextEventPrediction() { + // NOTE: We're basically echoing the database state here, so this won't + // necessarily be accurate if the caller just updated the object but has + // not saved it yet. That's a weird use case and would require more + // gymnastics, so don't bother trying to get it totally correct for now. + + if ($this->getEvent()) { + return $this->getEvent()->getNextEpoch(); + } else { + return $this->getNextEventEpoch(null, $is_reschedule = false); + } + } + + /* -( PhabricatorDestructibleInterface )----------------------------------- */