update:更新定时任务配置和初始化数据

This commit is contained in:
JaguarJack 2020-09-16 10:14:27 +08:00
parent a98fbdc7a1
commit c72943da58
4 changed files with 266 additions and 66 deletions

View File

@ -0,0 +1,253 @@
<?php
// +----------------------------------------------------------------------
// | CatchAdmin [Just Like ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~{$year} http://catchadmin.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
// +----------------------------------------------------------------------
// | Author: JaguarJack [ njphper@gmail.com ]
// +----------------------------------------------------------------------
use think\migration\Seeder;
class MonitorMenusSeed extends Seeder
{
/**
* Run Method.
*
* Write your database seeder using this method.
*
* More information on writing seeders is available here:
* http://docs.phinx.org/en/latest/seeding.html
*/
public function run()
{
\catcher\Utils::importTreeData($this->getPermissions(), 'permissions', 'parent_id');
}
protected function getPermissions()
{
return array (
0 =>
array (
'id' => 103,
'permission_name' => '系统监控',
'parent_id' => 0,
'level' => '',
'route' => '/monitor',
'icon' => 'el-icon-view',
'module' => 'monitor',
'creator_id' => 1,
'permission_mark' => 'monitor',
'component' => 'layout',
'redirect' => '/monitor/crontab',
'keepalive' => 1,
'type' => 1,
'hidden' => 1,
'sort' => 1,
'created_at' => 1600126383,
'updated_at' => 1600136975,
'deleted_at' => 0,
'children' =>
array (
0 =>
array (
'id' => 104,
'permission_name' => '定时任务',
'parent_id' => 103,
'level' => '103',
'route' => '/monitor/crontab',
'icon' => 'el-icon-time',
'module' => 'monitor',
'creator_id' => 1,
'permission_mark' => 'crontab',
'component' => 'crontab',
'redirect' => '',
'keepalive' => 1,
'type' => 1,
'hidden' => 1,
'sort' => 1,
'created_at' => 1600126931,
'updated_at' => 1600136975,
'deleted_at' => 0,
'children' =>
array (
0 =>
array (
'id' => 105,
'permission_name' => '列表',
'parent_id' => 104,
'level' => '103-104',
'route' => '',
'icon' => '',
'module' => 'monitor',
'creator_id' => 1,
'permission_mark' => 'crontab@index',
'component' => '',
'redirect' => '',
'keepalive' => 1,
'type' => 2,
'hidden' => 1,
'sort' => 1,
'created_at' => 1600127069,
'updated_at' => 1600136975,
'deleted_at' => 0,
),
1 =>
array (
'id' => 106,
'permission_name' => '保存',
'parent_id' => 104,
'level' => '103-104',
'route' => '',
'icon' => '',
'module' => 'monitor',
'creator_id' => 1,
'permission_mark' => 'crontab@save',
'component' => '',
'redirect' => '',
'keepalive' => 1,
'type' => 2,
'hidden' => 1,
'sort' => 1,
'created_at' => 1600127078,
'updated_at' => 1600136975,
'deleted_at' => 0,
),
2 =>
array (
'id' => 107,
'permission_name' => '更新',
'parent_id' => 104,
'level' => '103-104',
'route' => '',
'icon' => '',
'module' => 'monitor',
'creator_id' => 1,
'permission_mark' => 'crontab@update',
'component' => '',
'redirect' => '',
'keepalive' => 1,
'type' => 2,
'hidden' => 1,
'sort' => 1,
'created_at' => 1600127085,
'updated_at' => 1600136975,
'deleted_at' => 0,
),
3 =>
array (
'id' => 108,
'permission_name' => '删除',
'parent_id' => 104,
'level' => '103-104',
'route' => '',
'icon' => '',
'module' => 'monitor',
'creator_id' => 1,
'permission_mark' => 'crontab@delete',
'component' => '',
'redirect' => '',
'keepalive' => 1,
'type' => 2,
'hidden' => 1,
'sort' => 1,
'created_at' => 1600127091,
'updated_at' => 1600136975,
'deleted_at' => 0,
),
4 =>
array (
'id' => 109,
'permission_name' => '禁用/启用',
'parent_id' => 104,
'level' => '103-104',
'route' => '',
'icon' => '',
'module' => 'monitor',
'creator_id' => 1,
'permission_mark' => 'crontab@disOrEnable',
'component' => '',
'redirect' => '',
'keepalive' => 1,
'type' => 2,
'hidden' => 1,
'sort' => 1,
'created_at' => 1600129279,
'updated_at' => 1600136975,
'deleted_at' => 0,
),
),
),
1 =>
array (
'id' => 110,
'permission_name' => '任务日志',
'parent_id' => 103,
'level' => '103-104',
'route' => '/monitor/crontab/log/:crontab_id?',
'icon' => 'el-icon-guide',
'module' => 'monitor',
'creator_id' => 1,
'permission_mark' => 'CrontabLog',
'component' => 'crontabLog',
'redirect' => '',
'keepalive' => 1,
'type' => 1,
'hidden' => 2,
'sort' => 1,
'created_at' => 1600167562,
'updated_at' => 1600188651,
'deleted_at' => 0,
'children' =>
array (
0 =>
array (
'id' => 111,
'permission_name' => '列表',
'parent_id' => 110,
'level' => '103-104-110',
'route' => '',
'icon' => '',
'module' => 'monitor',
'creator_id' => 1,
'permission_mark' => 'CrontabLog@index',
'component' => '',
'redirect' => '',
'keepalive' => 1,
'type' => 2,
'hidden' => 1,
'sort' => 1,
'created_at' => 1600167574,
'updated_at' => 1600168082,
'deleted_at' => 0,
),
1 =>
array (
'id' => 112,
'permission_name' => '删除',
'parent_id' => 110,
'level' => '103-104-110',
'route' => '',
'icon' => '',
'module' => 'monitor',
'creator_id' => 1,
'permission_mark' => 'CrontabLog@delete',
'component' => '',
'redirect' => '',
'keepalive' => 1,
'type' => 2,
'hidden' => 1,
'sort' => 1,
'created_at' => 1600167581,
'updated_at' => 1600168082,
'deleted_at' => 0,
),
),
),
),
),
);
}
}

View File

@ -78,31 +78,23 @@ return [
], ],
/** /**
* 任务调度配置 *
* 定时任务配置
*
*/ */
'schedule' => [ 'crontab' => [
/** /**
* 常驻 worker 数量 * 存储目录
*/ */
'static_worker_number' => 4, 'store_path' => runtime_path('catch/crontab'),
/** /**
* 动态可扩展 worker 最大数量 * 主进程 pid 存储
*/ */
'max_worker_number' => 10, 'master_pid_file' => runtime_path('catch/crontab') . 'master.pid',
/** /**
* 存储位置 * 日志配置
*/
'store_path' => runtime_path('catch/schedule'),
/**
* 主进程 ID
*/
'master_pid_file' => runtime_path('catch/schedule') . 'master.pid',
/**
* 日志记录
*/ */
'log' => [ 'log' => [
// 日志记录方式 // 日志记录方式
@ -127,6 +119,9 @@ return [
'realtime_write' => false, 'realtime_write' => false,
], ],
'schedule_kernel' => \catcher\library\ScheduleKernel::class, /**
* crontab 任务命名空间
*/
'task_namespace' => '',
], ],
]; ];

View File

@ -1,10 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | CatchAdmin [Just Like ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
// +----------------------------------------------------------------------
// | Author: JaguarJack [ njphper@gmail.com ]
// +----------------------------------------------------------------------

View File

@ -1,38 +0,0 @@
<?php
// +----------------------------------------------------------------------
// | CatchAdmin [Just Like ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
// +----------------------------------------------------------------------
// | Author: JaguarJack [ njphper@gmail.com ]
// +----------------------------------------------------------------------
namespace catcher\library;
use catcher\library\crontab\Schedule;
class ScheduleKernel
{
protected $schedule;
public function __construct()
{
$this->schedule = new Schedule();
}
protected function run()
{
$this->schedule->command('catch:cache')->everyThirtySeconds();
$this->schedule->command('test')->everyTenSeconds();
}
public function tasks()
{
$this->run();
return $this->schedule->getCronTask();
}
}