Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update #2

Merged
merged 74 commits into from
Dec 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
4bb9a74
优化以数组配置的精确时间定时器解析的规则
osgochina Jan 27, 2016
d4703d9
fixbug #17
osgochina Jan 27, 2016
9c18044
删除delay
osgochina Feb 23, 2016
f96ebd3
改造开始
osgochina Aug 19, 2016
addb223
完成worker进程的任务运行
osgochina Aug 22, 2016
e5a5c13
完成worker进程的任务运行
osgochina Aug 22, 2016
9fc2fa3
centre通知任务给worker
osgochina Aug 29, 2016
93b772d
centre通知任务给worker
osgochina Aug 30, 2016
956ba82
worker执行完任务以后通知centre
osgochina Aug 31, 2016
26d4ef3
完成任务生命周期的日志记录
osgochina Aug 31, 2016
e72197e
初步可用版本完成
osgochina Sep 1, 2016
e83c430
重新设置结构
osgochina Sep 1, 2016
fb758e7
修改gettasklist api
osgochina Sep 2, 2016
3f2b2dc
v1.0版本完工
osgochina Oct 23, 2016
95f4916
v1.0版本完工 修改readme
osgochina Oct 23, 2016
2987719
修改readme
osgochina Oct 23, 2016
a584331
修复并发任务数限制
osgochina Oct 25, 2016
f8183d2
增加v0.8入口
osgochina Oct 25, 2016
9c6ee41
增加统计配置
osgochina Oct 25, 2016
6ecc19c
添加crontab 命令图形编辑器
osgochina Oct 26, 2016
2db7eed
Merge branch 'v1.0'
osgochina Oct 26, 2016
4c04a6c
1.fixbug #30 命令被转义
osgochina Nov 11, 2016
4770468
新增通过服务器查询其所有的任务列表
osgochina Nov 11, 2016
11c966c
修复bug
osgochina Dec 12, 2016
6b44a9a
fixbug
osgochina Dec 12, 2016
a71da24
修复定时器秒位置设为0的时候不执行的bug,修改成了设置为0默认是1秒执行
osgochina Jan 12, 2017
5869f8e
修复agent子进程句柄未清理问题
osgochina Feb 27, 2017
a3e1cb3
修复定时格式解析问题,这个问题会造成秒级设置不精确
osgochina Mar 1, 2017
5c52ca9
优化展示
osgochina Mar 2, 2017
aed3992
完善定时器的精度
osgochina Jun 13, 2017
6331a74
修改agent运行模式
osgochina Jul 12, 2017
9b80b7f
修改agent运行模式
osgochina Jul 12, 2017
d8bbb60
完善agent
osgochina Jul 13, 2017
a9cbdd1
清除日志
osgochina Jul 14, 2017
24c6388
增加群号
osgochina Jul 14, 2017
9a6c862
修改sql文件
osgochina Jul 17, 2017
a35dcd4
修改默认环境
osgochina Jul 17, 2017
ffea7d6
修改默认环境
osgochina Jul 17, 2017
cc2f48c
完善文档
osgochina Jul 17, 2017
0f80439
完善文档
osgochina Jul 18, 2017
0ec2daf
完善文档
osgochina Jul 18, 2017
2e8dbd2
删除管理agent的port,现有逻辑已经不需要了
osgochina Jul 19, 2017
6ee6b64
添加扩展依赖提示
osgochina Jul 19, 2017
9224ed7
支持32位系统
osgochina Jul 19, 2017
b2ef944
修改定时规则长度
osgochina Jul 20, 2017
22c2dd5
添加默认界面
osgochina Jul 20, 2017
9163b78
修改了数量配置信息
osgochina Jul 20, 2017
0398018
先清理,再载入
osgochina Jul 21, 2017
9f58987
fixbug
osgochina Jul 21, 2017
ec3cb8b
fixbug
osgochina Jul 21, 2017
05db692
fixbug
osgochina Jul 21, 2017
47a03eb
fixbug
osgochina Jul 21, 2017
e9fcb7c
修复了周设置的bug
osgochina Jul 25, 2017
4243cf8
下阶段功能安排
osgochina Aug 3, 2017
a705080
fixbug 修复执行的命令中不能有单引号和双引号的问题
osgochina Aug 17, 2017
2947a94
Update README.md
osgochina Aug 24, 2017
ac29b23
优化同一机器多agent注册模式,现变成
osgochina Sep 5, 2017
c7e2843
Merge remote-tracking branch 'origin/master'
osgochina Sep 5, 2017
d818fa3
fixbug #46
osgochina Sep 6, 2017
5887905
fixbug
osgochina Sep 13, 2017
0036597
fixbug #47
osgochina Sep 25, 2017
c2ea02b
fixbug #48
osgochina Sep 25, 2017
6298424
增加任务超时功能呢
osgochina Oct 27, 2017
5d5c842
增加任务超时功能呢
osgochina Oct 27, 2017
4335d29
增加任务超时功能呢
osgochina Oct 27, 2017
3fa13a5
fixbug 清理超时任务
osgochina Nov 23, 2017
8f0d124
fixbug 清理超时任务,增加任务清理逻辑
osgochina Nov 27, 2017
1da8653
Update crontab.sql
sky-L Jan 18, 2018
ab0b056
修复 0-59/10 秒 这种格式产生的任务,在0秒精度丢失的问题
osgochina Mar 19, 2018
b431627
修复添加任务 表达式生成器回显问题 undefined 以及周期radio选不中问题
Aug 14, 2018
38375b4
修复Agent和Center网络断开重连连接不上的问题。
Aug 14, 2018
f48bc14
修复Agent和Center网络断开重连连接不上的问题。
Aug 14, 2018
02a3b9f
Merge pull request #52 from sky-L/patch-1
osgochina Aug 14, 2018
c8a1888
Merge pull request #54 from igaojie/master
osgochina Aug 14, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.js linguist-language=php
*.css linguist-language=php
*.html linguist-language=php
170 changes: 96 additions & 74 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@ Swoole-Crontab(基于Swoole扩展)
+ 基于swoole的定时器程序,支持秒级处理.
+ 异步多进程处理。
+ 完全兼容crontab语法,且支持秒的配置,可使用数组规定好精确操作时间
+ 请使用swoole扩展1.7.9-stable及以上版本.[Swoole](https://github.com/swoole/swoole-src)
+ 支持worker处理redis队列任务
+ 单中心-多客户端模式,能够横向扩展
+ web界面管理,增删改查任务,完整的权限控制.
+ 请使用swoole扩展1.8.0+
+ [v0.8版本入口](https://github.com/osgochina/swoole-crontab/tree/v0.8)

2.配置的支持
2.架构图
--------------
![](https://raw.githubusercontent.com/osgochina/swoole-crontab/master/doc/x.png)

3.Crontab配置
--------------
具体配置文件请看 [src/config/crontab.php](https://github.com/osgochina/swoole-crontab/blob/master/src/config/crontab.php)
介绍一下时间配置

0 1 2 3 4 5
Expand All @@ -21,75 +26,92 @@ Swoole-Crontab(基于Swoole扩展)
| | +---------- hour (0 - 23)
| +------------ min (0 - 59)
+-------------- sec (0-59)[可省略,如果没有0位,则最小时间粒度是分钟]
3.帮助信息
----------
* Usage: /path/to/php main.php [options] -- [args...]

* -h [--help] 显示帮助信息
* -p [--pid] 指定pid文件位置(默认pid文件保存在当前目录)
* -s start 启动进程
* -s stop 停止进程
* -s restart 重启进程
* -l [--log] log文件夹的位置
* -c [--config] config文件的位置
* -d [--daemon] 是否后台运行
* -r [--reload] 重新载入配置文件
* -m [--monitor] 监控进程是否在运行,如果在运行则不管,未运行则启动进程
* --worker 开启worker 可以针对redis队列读取并编写处理逻辑
* --tasktype task任务获取类型,[file|mysql] 默认是file
* --checktime 默认精确对时(如果精确对时,程序则会延时到分钟开始0秒启动) 值为false则不精确对时


4.worker进程配置
-----------------
在src/config/worker.php 中写入配置,并且启动的时候加上 --worker选项就能启动worker工作进程
配置如下:

return array(
//key是要加载的worker类名
"ReadBook"=>array(
"name"=>"队列1", //备注名
"processNum"=>1, //启动的进程数量
"redis"=>array(
"host"=>"127.0.0.1", // redis ip
"port"=>6379, // redis端口
"timeout"=>30, // 链接超时时间
"db"=>0, // redis的db号
"queue"=>"abc" // redis队列名
)
)
);
具体的业务逻辑在src/worker/ 文件夹下。可以自己定义业务逻辑类,只需要继承WorkerBase.class.php中的WorkerBase基类就可以


5.例子

4.开始使用
-----------
你可以在配置文件中加上以下配置:

return array(
'taskid1' =>
array(
'taskname' => 'php -i', //任务名称
'rule' => '* * * * * *',//定时规则,可以使用数组精确设置时间 如:array("22:18","2015-11-11 00:00:00 ","10:20:39")
"unique" => 2, //排他数量,如果已经有这么多任务在执行,即使到了下一次执行时间,也不执行
'execute' => 'Cmd',//命令处理类
'args' =>
array(
'cmd' => 'php -i',//命令
"ext": ""
),
),
);
然后去到src目录下,执行

/path/to/php main.php -s start

执行完成以后你就可以在/tmp/test.log看到输出了,每秒输出一次

如果你需要写自己的代码逻辑,你也可以到plugin目录下,实现一个PluginBase.class.php接口的类.
在其中写自己的逻辑代码。

6.TODO
1.修改配置

1.1 中心服配置

/path/to/src/center/configs/dev/db.php 修改数据库配置
进入mysql数据库执行/path/to/doc/crontab.sql 的sql文件
src/center/_init.php 修改 PUBLIC_PATH swoole framework框架所在的路径

1.2 admin管理后台的配置文件修改

src/admin/configs/dev/db.php 修改数据库配置
src/admin/configs/dev/service.php 中心服启动时候监听的ip端口,需要跟中心服通讯
src/public/index.php
修改 WEBROOT 域名
修改 PUBLIC_PATH swoole framework框架所在的路径


2.下载swoole framework框架到本地/data/www/public/ [framework](https://github.com/swoole/framework.git)

3.配置nginx,列子如下:

```
server {
listen 80;
server_name crontab.test.com;

root /data/www/wwwroot/swoole-crontab/src/public;

index index.php index.html;
location / {
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php;
}
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

}
```

4.启动中心服

/path/to/php /path/to/src/center/center.php start -d -h 127.0.0.1 -p 8901

5.启动客户端

-h 是指中心服地址 -p 中心服端口
/path/to/php /path/to/src/agent/agent.php start -d -h 127.0.0.1 -p 8901

6.web界面访问

>输入nginx配置的地址访问web界面,默认用户名/密码是admin/admin

7.操作步骤

请按照以上步骤操作,因为admin后台是通过接口连接上中心服来进行管理.所以必须先启动中心服,再打开admin管理后台



4.使用交流
-----------

1.后台截图

![](https://raw.githubusercontent.com/osgochina/swoole-crontab/master/doc/demo.png)

2.更加清晰的架构图.感谢@xufei100

![](https://raw.githubusercontent.com/osgochina/swoole-crontab/master/doc/xufei100.png)


QQ群:560807006

5.TODO
----------
+ 分布式运行
+ restful增删改任务

- [ ] 去除nginx依赖
- [ ] 配置文件统一
- [ ] 去除swoole framework框架的依赖
- [ ] restful api接口
- [ ] 通过命令行管理任务
- [ ] 无中心服依赖
54 changes: 54 additions & 0 deletions bin/build.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/local/bin/php
<?php
if (empty($argv[1]))
{
$dst = 'agent';
}
else
{
$dst = trim($argv[1]);
}

if ($dst == 'agent')
{
$pharFile = __DIR__ . '/agent.phar';
if (file_exists($pharFile)) unlink($pharFile);
$phar = new Phar($pharFile);
$phar->buildFromDirectory(dirname(__DIR__) . "/src/agent/");
//$phar->compressFiles(\Phar::GZ);
$phar->stopBuffering();
$phar->setStub($phar->createDefaultStub('agent.php'));
echo "agent.phar打包成功\n";
}
elseif ($dst == 'centre')
{
$pharFile = __DIR__ . '/crontab-centre.phar';
if (file_exists($pharFile)) unlink($pharFile);
$phar = new Phar($pharFile);
$phar->buildFromDirectory(dirname(__DIR__) . "/src/center/");
//$phar->compressFiles(\Phar::GZ);
$phar->stopBuffering();
$phar->setStub($phar->createDefaultStub('centre.php'));
echo "crontab-center.phar打包成功\n";
}
elseif ($dst == 'phar')
{
if (empty($argv[2]))
{
die("使用方法:php {$argv[0]} {$argv[1]} 源码目录\n");
}

if (!is_dir($argv[2]))
{
die("目录({$argv[2]})不存在\n");
}
$dirname = basename($argv[2]);
$filename = $dirname . '.phar';
$pharFile = __DIR__ . '/'.$filename;
$phar = new Phar($pharFile);
$phar->buildFromDirectory($argv[2]);
$phar->compressFiles(\Phar::GZ);
$phar->stopBuffering();
$phar->setStub($phar->createDefaultStub('main.php'));
echo "{$filename}打包成功\n";
}
Loading