Skip to content

[8.x] Add ScheduledBackgroundTaskFinished event to fire on completion of background tasks #37367

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/Illuminate/Console/Events/ScheduledBackgroundTaskFinished.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 ScheduledBackgroundTaskFinished
{
/**
* The scheduled event that ran.
*
* @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;
}
}
11 changes: 9 additions & 2 deletions src/Illuminate/Console/Scheduling/ScheduleFinishCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Illuminate\Console\Scheduling;

use Illuminate\Console\Command;
use Illuminate\Console\Events\ScheduledBackgroundTaskFinished;
use Illuminate\Contracts\Events\Dispatcher;

class ScheduleFinishCommand extends Command
{
Expand Down Expand Up @@ -31,12 +33,17 @@ class ScheduleFinishCommand extends Command
* Execute the console command.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @param \Illuminate\Contracts\Events\Dispatcher $dispatcher
* @return void
*/
public function handle(Schedule $schedule)
public function handle(Schedule $schedule, Dispatcher $dispatcher)
{
collect($schedule->events())->filter(function ($value) {
return $value->mutexName() == $this->argument('id');
})->each->callAfterCallbacksWithExitCode($this->laravel, $this->argument('code'));
})->each(function ($event) use ($dispatcher) {
$event->callafterCallbacksWithExitCode($this->laravel, $this->argument('code'));

$dispatcher->dispatch(new ScheduledBackgroundTaskFinished($event));
});
}
}