From 84c85c3d122583486bcabfe01fdd388cd67b0707 Mon Sep 17 00:00:00 2001 From: JaguarJack Date: Mon, 8 Feb 2021 10:25:03 +0800 Subject: [PATCH] =?UTF-8?q?fixed:=E4=BF=AE=E5=A4=8D=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E7=AB=8B=E5=8D=B3=E6=89=A7=E8=A1=8C=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E4=BB=BB=E5=8A=A1=E6=89=A7=E8=A1=8C=E6=B7=B7=E4=B9=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- catch/monitor/command/ScheduleCommand.php | 10 +++++----- catch/monitor/controller/Crontab.php | 4 ++-- .../migrations/20200914203553_crontab.php | 20 +++++++++---------- catch/monitor/model/Crontab.php | 3 +-- 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/catch/monitor/command/ScheduleCommand.php b/catch/monitor/command/ScheduleCommand.php index ecaee21..4c32861 100644 --- a/catch/monitor/command/ScheduleCommand.php +++ b/catch/monitor/command/ScheduleCommand.php @@ -96,13 +96,14 @@ class ScheduleCommand extends Command { $executeAbleCommands = []; + Crontab::where('status', Crontab::ENABLE) - ->where('tactics', '<>', Crontab::EXECUTE_FORBIDDEN) ->select() ->each(function ($command) use (&$executeAbleCommands){ if ($command->tactics == Crontab::EXECUTE_IMMEDIATELY) { $executeAbleCommands[] = $command; - return true; + $command->tactics = Crontab::EXECUTE_NORMAL; + return $command->save(); } $can = date('Y-m-d H:i', @@ -113,9 +114,8 @@ class ScheduleCommand extends Command if ($can) { // 如果任务只执行一次 之后禁用该任务 if ($command->tactics === Crontab::EXECUTE_ONCE) { - Crontab::where('id', $command->id)->update([ - 'status' => Crontab::DISABLE, - ]); + $command->tactics = Crontab::DISABLE; + $command->save(); } $executeAbleCommands[] = $command; diff --git a/catch/monitor/controller/Crontab.php b/catch/monitor/controller/Crontab.php index 57458a6..36daa13 100644 --- a/catch/monitor/controller/Crontab.php +++ b/catch/monitor/controller/Crontab.php @@ -47,7 +47,7 @@ class Crontab extends CatchController */ public function save(Request $request) { - CronExpression::factory($request->post('cron')); + new CronExpression($request->post('cron')); return CatchResponse::success($this->model->storeBy($request->post())); } @@ -73,7 +73,7 @@ class Crontab extends CatchController */ public function update(Request $request, $id) { - CronExpression::factory($request->post('cron')); + new CronExpression($request->post('cron')); return CatchResponse::success($this->model->updateBy($id, $request->post())); } diff --git a/catch/monitor/database/migrations/20200914203553_crontab.php b/catch/monitor/database/migrations/20200914203553_crontab.php index b41ecae..1ff27f3 100644 --- a/catch/monitor/database/migrations/20200914203553_crontab.php +++ b/catch/monitor/database/migrations/20200914203553_crontab.php @@ -30,16 +30,16 @@ class Crontab extends Migrator public function change() { $table = $this->table('crontab', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '定时任务' ,'id' => 'id','signed' => true ,'primary_key' => ['id']]); - $table->addColumn('name', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => false,'comment' => '任务名称',]) - ->addColumn('group', 'boolean', ['null' => false,'default' => 1,'signed' => false,'comment' => '1 默认 2 系统',]) - ->addColumn('task', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => false,'comment' => '任务名称',]) - ->addColumn('cron', 'string', ['limit' => 50,'null' => false,'default' => '','signed' => false,'comment' => 'cron 表达式',]) - ->addColumn('tactics', 'boolean', ['null' => false,'default' => 1,'signed' => false,'comment' => '1 立即执行 2 执行一次 3 放弃执行',]) - ->addColumn('status', 'boolean', ['null' => false,'default' => 1,'signed' => false,'comment' => '1 正常 2 禁用',]) - ->addColumn('remark', 'string', ['limit' => 1000,'null' => false,'default' => '','signed' => false,'comment' => '备注',]) - ->addColumn('creator_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => true,'comment' => '创建人ID',]) - ->addColumn('created_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => true,'comment' => '创建时间',]) - ->addColumn('updated_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => true,'comment' => '更新时间',]) + $table->addColumn('name', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => false,'comment' => '任务名称',]) + ->addColumn('group', 'boolean', ['null' => false,'default' => 1,'signed' => false,'comment' => '1 默认 2 系统',]) + ->addColumn('task', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => false,'comment' => '任务名称',]) + ->addColumn('cron', 'string', ['limit' => 50,'null' => false,'default' => '','signed' => false,'comment' => 'cron 表达式',]) + ->addColumn('tactics', 'boolean', ['null' => false,'default' => 1,'signed' => false,'comment' => '1 立即执行 2 执行一次 3 正常执行',]) + ->addColumn('status', 'boolean', ['null' => false,'default' => 1,'signed' => false,'comment' => '1 正常 2 禁用',]) + ->addColumn('remark', 'string', ['limit' => 1000,'null' => false,'default' => '','signed' => false,'comment' => '备注',]) + ->addColumn('creator_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => true,'comment' => '创建人ID',]) + ->addColumn('created_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => true,'comment' => '创建时间',]) + ->addColumn('updated_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => true,'comment' => '更新时间',]) ->addColumn('deleted_at', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => true,'comment' => '软删除',]) ->create(); } diff --git a/catch/monitor/model/Crontab.php b/catch/monitor/model/Crontab.php index 77b6a9a..66c3445 100644 --- a/catch/monitor/model/Crontab.php +++ b/catch/monitor/model/Crontab.php @@ -38,6 +38,5 @@ class Crontab extends Model const EXECUTE_IMMEDIATELY = 1; // 立即执行 const EXECUTE_ONCE = 2; // 执行一次 - const EXECUTE_FORBIDDEN = 3; // 停止执行 - + const EXECUTE_NORMAL = 3; // 正常执行 } \ No newline at end of file