Update configuration arguments and invalidate 2 years of waiting

[MAILPOET-4418]
This commit is contained in:
David Remer
2022-07-28 09:49:02 +03:00
committed by Veljko V
parent a9a35333c4
commit 83c7f7bc7f
2 changed files with 136 additions and 2 deletions

View File

@@ -28,7 +28,7 @@ class DelayAction implements Action {
}
public function run(Workflow $workflow, WorkflowRun $workflowRun, Step $step): void {
$this->actionScheduler->schedule(time() + $step->getArgs()['seconds'], Hooks::WORKFLOW_STEP, [
$this->actionScheduler->schedule(time() + $this->calculateSeconds($step), Hooks::WORKFLOW_STEP, [
[
'workflow_run_id' => $workflowRun->getId(),
'step_id' => $step->getNextStepId(),
@@ -39,6 +39,22 @@ class DelayAction implements Action {
}
public function isValid(array $subjects, Step $step, Workflow $workflow): bool {
return (int)($step->getArgs()['seconds'] ?? null) > 0;
$seconds = $this->calculateSeconds($step);
return $seconds > 0 && $seconds < 2 * YEAR_IN_SECONDS;
}
private function calculateSeconds(Step $step): int {
$delay = (int)($step->getArgs()['delay'] ?? null);
switch ($step->getArgs()['delay_type']) {
case "HOURS":
return $delay * HOUR_IN_SECONDS;
case "DAYS":
return $delay * DAY_IN_SECONDS;
case "WEEKS":
return $delay * WEEK_IN_SECONDS;
default:
return 0;
}
}
}