新增 crontab 组件

This commit is contained in:
JaguarJack
2020-07-07 16:58:34 +08:00
parent f15eedfa9c
commit 4fec98f939
7 changed files with 883 additions and 100 deletions

View File

@@ -8,3 +8,58 @@
// +----------------------------------------------------------------------
// | Author: JaguarJack [ njphper@gmail.com ]
// +----------------------------------------------------------------------
namespace catcher\library\crontab;
use catcher\exceptions\FailedException;
class Schedule
{
protected $crons = [];
/**
* 新增 command 任务
*
* @time 2020年07月04日
* @param $command
* @param array $arguments
* @return Cron
*/
public function command($command, $arguments = []): Cron
{
$this->crons[] = $cron = new Cron($command);
return $cron;
}
/**
* 新增 task 任务
*
* @time 2020年07月04日
* @param $task
* @param array $argument
* @return Cron
*/
public function task($task, $argument = []): Cron
{
if (is_string($task)) {
if (!class_exists($task)) {
throw new FailedException("[$task] not found");
}
$task = new $task(...$argument);
}
$this->crons[] = $cron = new Cron($task);
return $cron;
}
public function getCronTask()
{
return $this->crons;
}
}