Skip to content

Commit

Permalink
Dispatch event when a scheduled command was filtered from running (#3…
Browse files Browse the repository at this point in the history
…0407)

If a scheduled command is run with a truth constraint, it is not simple
to check whether the task didn't run at all, or if it was filtered
running from a known system constraint.

Firing an event when the task is intentionally skipped allows monitoring
over the task executing as scheduled, based on the truth constraint.
  • Loading branch information
michaeldyrynda authored and taylorotwell committed Oct 24, 2019
1 parent e3880cf commit f4985df
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/Illuminate/Console/Events/ScheduledTaskSkipped.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Illuminate\Console\Events;

use Illuminate\Console\Scheduling\Event;

class ScheduledTaskSkipped
{
/**
* The scheduled event being run.
*
* @var \Illuminate\Console\Scheduling\Event
*/
public $task;

/**
* Create a new event instance.
*
* @param \Illuminate\Console\Scheduling\Event $task
* @return void
*/
public function __construct(Event $task)
{
$this->task = $task;
}
}
3 changes: 3 additions & 0 deletions src/Illuminate/Console/Scheduling/ScheduleRunCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Console\Command;
use Illuminate\Console\Events\ScheduledTaskFinished;
use Illuminate\Console\Events\ScheduledTaskSkipped;
use Illuminate\Console\Events\ScheduledTaskStarting;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Support\Facades\Date;
Expand Down Expand Up @@ -78,6 +79,8 @@ public function handle(Schedule $schedule, Dispatcher $dispatcher)

foreach ($this->schedule->dueEvents($this->laravel) as $event) {
if (! $event->filtersPass($this->laravel)) {
$this->dispatcher->dispatch(new ScheduledTaskSkipped($event));

continue;
}

Expand Down

0 comments on commit f4985df

Please sign in to comment.