Skip to content

Commit

Permalink
[8.x] add schedule:clear-mutex command (#40135)
Browse files Browse the repository at this point in the history
* add clear mutex command

* formatting

* alphabetize

Co-authored-by: Bernard Wiesner <[email protected]>
Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
3 people authored Dec 22, 2021
1 parent 994dbac commit c3ce974
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/Illuminate/Console/Scheduling/ScheduleClearCacheCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Illuminate\Console\Scheduling;

use Illuminate\Console\Command;

class ScheduleClearCacheCommand extends Command
{
/**
* The console command name.
*
* @var string
*/
protected $name = 'schedule:clear-cache';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Delete the cached mutex files created by scheduler';

/**
* Execute the console command.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
public function handle(Schedule $schedule)
{
$mutexCleared = false;

foreach ($schedule->events($this->laravel) as $event) {
if ($event->mutex->exists($event)) {
$this->line('<info>Deleting mutex for:</info> '.$event->command);

$event->mutex->forget($event);

$mutexCleared = true;
}
}

if (! $mutexCleared) {
$this->info('No mutex files were found.');
}
}
}
12 changes: 12 additions & 0 deletions src/Illuminate/Foundation/Providers/ArtisanServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Cache\Console\CacheTableCommand;
use Illuminate\Cache\Console\ClearCommand as CacheClearCommand;
use Illuminate\Cache\Console\ForgetCommand as CacheForgetCommand;
use Illuminate\Console\Scheduling\ScheduleClearCacheCommand;
use Illuminate\Console\Scheduling\ScheduleFinishCommand;
use Illuminate\Console\Scheduling\ScheduleListCommand;
use Illuminate\Console\Scheduling\ScheduleRunCommand;
Expand Down Expand Up @@ -127,6 +128,7 @@ class ArtisanServiceProvider extends ServiceProvider implements DeferrableProvid
'ScheduleFinish' => ScheduleFinishCommand::class,
'ScheduleList' => ScheduleListCommand::class,
'ScheduleRun' => ScheduleRunCommand::class,
'ScheduleClearCache' => ScheduleClearCacheCommand::class,
'ScheduleTest' => ScheduleTestCommand::class,
'ScheduleWork' => ScheduleWorkCommand::class,
'StorageLink' => 'command.storage.link',
Expand Down Expand Up @@ -968,6 +970,16 @@ protected function registerSeedCommand()
});
}

/**
* Register the command.
*
* @return void
*/
protected function registerScheduleClearCacheCommand()
{
$this->app->singleton(ScheduleClearCacheCommand::class);
}

/**
* Register the command.
*
Expand Down

0 comments on commit c3ce974

Please sign in to comment.