Skip to content

Commit d899417

Browse files
authored
[FEATURE] Determine the current time before the first task is run, to support long-running tasks (#51)
Closes #49
1 parent 9c643da commit d899417

3 files changed

Lines changed: 14 additions & 0 deletions

File tree

Task/Schedule.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,14 @@ public function setPart(int $position, string $value): self
161161
*/
162162
public function isDue($currentTime = 'now'): bool
163163
{
164+
if (is_string($currentTime)) {
165+
trigger_deprecation(
166+
'rewieer/taskschedulerbundle',
167+
'0.12',
168+
'Calling isDue() with a string is deprecated, use a DateTimeInteface instance instead'
169+
);
170+
}
171+
164172
return $this->cron->isDue($currentTime);
165173
}
166174
}

Task/Scheduler.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
namespace Rewieer\TaskSchedulerBundle\Task;
1212

13+
use DateTime;
1314
use Rewieer\TaskSchedulerBundle\Event\EventDispatcher;
1415

1516
class Scheduler
@@ -39,6 +40,10 @@ public function run($currentTime = 'now'): void
3940
{
4041
$this->dispatcher->dispatch(SchedulerEvents::ON_START);
4142

43+
if (is_string($currentTime)) {
44+
$currentTime = new DateTime($currentTime);
45+
}
46+
4247
foreach ($this->tasks as $task) {
4348
if ($task->isDue($currentTime)) {
4449
$this->runTask($task);

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"keywords": ["cron", "task", "scheduler", "symfony", "bundle"],
1111
"require": {
1212
"php": "^7.4|^8.1",
13+
"symfony/deprecation-contracts": "^2.5|^3.4",
1314
"symfony/framework-bundle": "^5.4|^6.4|^7.0",
1415
"symfony/console": "^5.3|^6.4|^7.0",
1516
"dragonmantank/cron-expression": "^3.3"

0 commit comments

Comments
 (0)