Move automation completion to step scheduler
[MAILPOET-5569]
This commit is contained in:
@@ -181,20 +181,11 @@ class StepHandler {
|
|||||||
throw new InvalidStateException();
|
throw new InvalidStateException();
|
||||||
}
|
}
|
||||||
|
|
||||||
// next step scheduled by action
|
// schedule next step if not scheduled by action
|
||||||
if ($this->stepScheduler->hasScheduledNextStep($args)) {
|
if (!$this->stepScheduler->hasScheduledNextStep($args)) {
|
||||||
return;
|
$this->stepScheduler->scheduleNextStep($args);
|
||||||
}
|
}
|
||||||
|
|
||||||
// no need to schedule a new step if no next step exists
|
|
||||||
if (count($stepData->getNextSteps()) === 0) {
|
|
||||||
$this->automationRunStorage->updateNextStep($args->getAutomationRun()->getId(), null);
|
|
||||||
$this->automationRunStorage->updateStatus($automationRunId, AutomationRun::STATUS_COMPLETE);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// enqueue next step
|
|
||||||
$this->stepScheduler->scheduleNextStep($args);
|
|
||||||
// TODO: allow long-running steps (that are not done here yet)
|
// TODO: allow long-running steps (that are not done here yet)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace MailPoet\Automation\Engine\Control;
|
namespace MailPoet\Automation\Engine\Control;
|
||||||
|
|
||||||
|
use MailPoet\Automation\Engine\Data\AutomationRun;
|
||||||
use MailPoet\Automation\Engine\Data\StepRunArgs;
|
use MailPoet\Automation\Engine\Data\StepRunArgs;
|
||||||
use MailPoet\Automation\Engine\Hooks;
|
use MailPoet\Automation\Engine\Hooks;
|
||||||
use MailPoet\Automation\Engine\Storage\AutomationRunStorage;
|
use MailPoet\Automation\Engine\Storage\AutomationRunStorage;
|
||||||
@@ -23,8 +24,15 @@ class StepScheduler {
|
|||||||
|
|
||||||
public function scheduleNextStep(StepRunArgs $args, int $timestamp = null): int {
|
public function scheduleNextStep(StepRunArgs $args, int $timestamp = null): int {
|
||||||
$runId = $args->getAutomationRun()->getId();
|
$runId = $args->getAutomationRun()->getId();
|
||||||
$nextStep = $args->getStep()->getNextSteps()[0] ?? null;
|
|
||||||
$nextStepId = $nextStep ? $nextStep->getId() : null;
|
// complete the automation run if there are no more steps
|
||||||
|
if (count($args->getStep()->getNextSteps()) === 0) {
|
||||||
|
$this->automationRunStorage->updateNextStep($runId, null);
|
||||||
|
$this->automationRunStorage->updateStatus($runId, AutomationRun::STATUS_COMPLETE);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$nextStepId = $args->getStep()->getNextSteps()[0]->getId();
|
||||||
$data = $this->getActionData($runId, $nextStepId);
|
$data = $this->getActionData($runId, $nextStepId);
|
||||||
$id = $this->scheduleStepAction($data, $timestamp);
|
$id = $this->scheduleStepAction($data, $timestamp);
|
||||||
$this->automationRunStorage->updateNextStep($runId, $nextStepId);
|
$this->automationRunStorage->updateNextStep($runId, $nextStepId);
|
||||||
@@ -49,7 +57,7 @@ class StepScheduler {
|
|||||||
: $this->actionScheduler->schedule($timestamp, Hooks::AUTOMATION_STEP, $data);
|
: $this->actionScheduler->schedule($timestamp, Hooks::AUTOMATION_STEP, $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getActionData(int $runId, ?string $stepId): array {
|
private function getActionData(int $runId, string $stepId): array {
|
||||||
return [
|
return [
|
||||||
[
|
[
|
||||||
'automation_run_id' => $runId,
|
'automation_run_id' => $runId,
|
||||||
|
Reference in New Issue
Block a user