Skip to content

Commit

Permalink
refactor(scheduler): due tasks filter fixed (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
Guikingone authored May 12, 2021
1 parent 3001e48 commit 0ee98a5
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/Scheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function schedule(TaskInterface $task): void
$task->setScheduledAt($this->getSynchronizedCurrentDate());
$task->setTimezone($task->getTimezone() ?? $this->timezone);

if (null !== $this->bus && $task->isQueued()) {
if ($this->bus instanceof MessageBusInterface && $task->isQueued()) {
$this->bus->dispatch(new TaskMessage($task));
$this->dispatch(new TaskScheduledEvent($task));

Expand All @@ -99,7 +99,7 @@ public function unschedule(string $taskName): void
*/
public function yieldTask(string $name, bool $async = false): void
{
if ($async && null !== $this->bus) {
if ($async && $this->bus instanceof MessageBusInterface) {
$this->bus->dispatch(new TaskToYieldMessage($name));

return;
Expand All @@ -124,7 +124,7 @@ public function update(string $taskName, TaskInterface $task): void
*/
public function pause(string $taskName, bool $async = false): void
{
if ($async && null !== $this->bus) {
if ($async && $this->bus instanceof MessageBusInterface) {
$this->bus->dispatch(new TaskToPauseMessage($taskName));

return;
Expand All @@ -148,7 +148,7 @@ public function getDueTasks(): TaskListInterface
{
$synchronizedCurrentDate = $this->getSynchronizedCurrentDate();

$dueTasks = $this->transport->list()->filter(fn (TaskInterface $task): bool => (new CronExpression($task->getExpression()))->isDue($synchronizedCurrentDate, $task->getTimezone()->getName()) && (null !== $task->getLastExecution() && ($synchronizedCurrentDate->format('Y-m-d h:i') !== $task->getLastExecution()->format('Y-m-d h:i'))));
$dueTasks = $this->transport->list()->filter(fn (TaskInterface $task): bool => (new CronExpression($task->getExpression()))->isDue($synchronizedCurrentDate, $task->getTimezone()->getName()) && null === $task->getLastExecution() || $task->getLastExecution()->format('Y-m-d h:i') !== $synchronizedCurrentDate->format('Y-m-d h:i'));

return $dueTasks->filter(function (TaskInterface $task) use ($synchronizedCurrentDate): bool {
if ($task->getExecutionStartDate() instanceof DateTimeImmutable && $task->getExecutionEndDate() instanceof DateTimeImmutable) {
Expand Down Expand Up @@ -213,7 +213,7 @@ public function reboot(): void

private function dispatch(Event $event): void
{
if (null === $this->eventDispatcher) {
if (!$this->eventDispatcher instanceof EventDispatcherInterface) {
return;
}

Expand Down

0 comments on commit 0ee98a5

Please sign in to comment.