Cancel scheduled progress runs when executed manually

[MAILPOET-4977]
This commit is contained in:
Jan Jakes
2024-04-25 16:19:16 +02:00
committed by Aschepikov
parent a1bafad6f1
commit f71993dde9
4 changed files with 73 additions and 0 deletions

View File

@@ -2,6 +2,7 @@
namespace MailPoet\Automation\Engine\Control;
use ActionScheduler_CanceledAction;
use MailPoet\Automation\Engine\Data\AutomationRunLog;
use MailPoet\Automation\Engine\Exceptions;
use MailPoet\Automation\Engine\Hooks;
@@ -35,6 +36,19 @@ class AutomationController {
'step_id' => $stepId,
'run_number' => $runNumber,
];
// if a pending action exists, unschedule it
$this->actionScheduler->unscheduleAction(Hooks::AUTOMATION_STEP, [$args]);
// if an action still exists (pending, in-progress, complete, failed), it's an error
$actions = $this->actionScheduler->getScheduledActions(['hook' => Hooks::AUTOMATION_STEP, 'args' => [$args]]);
$processedActions = array_filter($actions, function ($action) {
return !$action instanceof ActionScheduler_CanceledAction;
});
if (count($processedActions) > 0) {
throw Exceptions::stepActionProcessed($stepId, $runId, $runNumber);
}
$this->actionScheduler->enqueue(Hooks::AUTOMATION_STEP, [$args]);
}
}