mirror of
https://github.com/flarum/core.git
synced 2025-10-11 23:14:29 +02:00
Include task scheduler in core
This commit is contained in:
committed by
Alexander Skvortsov
parent
d29495203b
commit
8dd57ffed2
@@ -15,6 +15,7 @@ use Illuminate\Contracts\Container\Container;
|
||||
class Console implements ExtenderInterface
|
||||
{
|
||||
protected $addCommands = [];
|
||||
protected $scheduled = [];
|
||||
|
||||
/**
|
||||
* Add a command to the console.
|
||||
@@ -28,10 +29,38 @@ class Console implements ExtenderInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule a command to run on an interval.
|
||||
*
|
||||
* @param string $command ::class attribute of command class, which must extend Flarum\Console\AbstractCommand
|
||||
* @param callable|string $callback
|
||||
*
|
||||
* The callback can be a closure or invokable class, and should accept:
|
||||
* - \Illuminate\Console\Scheduling\Event $event
|
||||
*
|
||||
* The callback should apply relevant methods to $event, and does not need to return anything.
|
||||
*
|
||||
* @see https://laravel.com/api/8.x/Illuminate/Console/Scheduling/Event.html
|
||||
* @see https://laravel.com/docs/8.x/scheduling#schedule-frequency-options
|
||||
* for more information on available methods and what they do.
|
||||
*
|
||||
* @param array $args An array of args to call the command with.
|
||||
*/
|
||||
public function schedule(string $command, $callback, $args = [])
|
||||
{
|
||||
$this->scheduled[] = compact('args', 'callback', 'command');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function extend(Container $container, Extension $extension = null)
|
||||
{
|
||||
$container->extend('flarum.console.commands', function ($existingCommands) {
|
||||
return array_merge($existingCommands, $this->addCommands);
|
||||
});
|
||||
|
||||
$container->extend('flarum.console.scheduled', function ($existingScheduled) {
|
||||
return array_merge($existingScheduled, $this->scheduled);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user