master

laravel/framework

Last updated at: 29/12/2023 09:21

ScheduleInterruptCommand.php

TLDR

The ScheduleInterruptCommand.php file is a class that extends the Command class from the Illuminate\Console namespace. It provides a command called schedule:interrupt that can be used to interrupt the current schedule run.

Methods

handle

This method is responsible for executing the console command. It puts a value in the cache with the key illuminate:schedule:interrupt and value true, which signals the interruption of the current schedule run. It also displays an information message using the components object.

Classes

ScheduleInterruptCommand

This class extends the Command class and represents the schedule:interrupt command. It has a protected property $name which represents the command name (schedule:interrupt) and a protected property $description which represents the command description ('Interrupt the current schedule run'). It also has a protected property $cache which is an instance of the Illuminate\Contracts\Cache\Repository interface.

The class has a constructor that injects an instance of the Illuminate\Contracts\Cache\Repository interface into the $cache property.

The class provides a handle method that executes the console command.

<?php

namespace Illuminate\Console\Scheduling;

use Illuminate\Console\Command;
use Illuminate\Contracts\Cache\Repository as Cache;
use Illuminate\Support\Facades\Date;
use Symfony\Component\Console\Attribute\AsCommand;

#[AsCommand(name: 'schedule:interrupt')]
class ScheduleInterruptCommand extends Command
{
    /**
     * The console command name.
     *
     * @var string
     */
    protected $name = 'schedule:interrupt';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Interrupt the current schedule run';

    /**
     * The cache store implementation.
     *
     * @var \Illuminate\Contracts\Cache\Repository
     */
    protected $cache;

    /**
     * Create a new schedule interrupt command.
     *
     * @param  \Illuminate\Contracts\Cache\Repository  $cache
     * @return void
     */
    public function __construct(Cache $cache)
    {
        parent::__construct();

        $this->cache = $cache;
    }

    /**
     * Execute the console command.
     *
     * @return void
     */
    public function handle()
    {
        $this->cache->put('illuminate:schedule:interrupt', true, Date::now()->endOfMinute());

        $this->components->info('Broadcasting schedule interrupt signal.');
    }
}