// Tasks **must not** be queued before their state in the database has been updated. Otherwise,
// a worker could have already fetched the task and set its state to running before it gets set to
// queued, thus breaking the task.
/** @var ScheduledTaskEntity $task */
foreach ($tasks as $task) { $this->
queueTask($task,
$context);
} } public function getNextExecutionTime(): ?\DateTimeInterface
{ $criteria =
$this->
buildCriteriaForNextScheduledTask();
/** @var AggregationResult $aggregation */
$aggregation =
$this->scheduledTaskRepository
->
aggregate($criteria, Context::
createDefaultContext()) ->
get('nextExecutionTime'
);
/** @var MinResult $aggregation */
if (!
$aggregation instanceof MinResult
) { return null;
} if ($aggregation->
getMin() === null
) { return null;
}