|
@@ -17,9 +17,12 @@ function start(){ |
|
@@ -17,9 +17,12 @@ function start(){ |
17
|
break;
|
17
|
break;
|
18
|
}
|
18
|
}
|
19
|
|
19
|
|
20
|
- $lists = db()->all(\Model\sendJobsSql::sendList());
|
20
|
+ $lists = db()->all(\Model\sendJobsSql::sendList(500-$cNum));
|
21
|
// 循环
|
21
|
// 循环
|
22
|
foreach ($lists as $list){
|
22
|
foreach ($lists as $list){
|
|
|
23
|
+
|
|
|
24
|
+ // 占用 id
|
|
|
25
|
+ if(redis()->add('send_job_run_id_'.$list['id'],$list['id'])){
|
23
|
go(function ($data) use (&$cNum){
|
26
|
go(function ($data) use (&$cNum){
|
24
|
$cNum++; // 协程数+1
|
27
|
$cNum++; // 协程数+1
|
25
|
// 表单数据
|
28
|
// 表单数据
|
|
@@ -87,15 +90,20 @@ function start(){ |
|
@@ -87,15 +90,20 @@ function start(){ |
87
|
}
|
90
|
}
|
88
|
|
91
|
|
89
|
// 协程结束后
|
92
|
// 协程结束后
|
90
|
- co::defer(function () use(&$cNum){
|
93
|
+ co::defer(function ($id) use(&$cNum,$data){
|
91
|
$cNum--;
|
94
|
$cNum--;
|
92
|
// 结束后要关闭数据库链接,不然链接一直暂用
|
95
|
// 结束后要关闭数据库链接,不然链接一直暂用
|
93
|
db()->close();
|
96
|
db()->close();
|
|
|
97
|
+ // 删除占用
|
|
|
98
|
+ redis()->delete('send_job_run_id_'.$data['id']);
|
94
|
redis()->close();
|
99
|
redis()->close();
|
95
|
});
|
100
|
});
|
96
|
|
101
|
|
97
|
},$list);
|
102
|
},$list);
|
98
|
}
|
103
|
}
|
|
|
104
|
+
|
|
|
105
|
+ }
|
|
|
106
|
+
|
99
|
}catch (Throwable $e){
|
107
|
}catch (Throwable $e){
|
100
|
logs($e->getMessage().$e->getTraceAsString());
|
108
|
logs($e->getMessage().$e->getTraceAsString());
|
101
|
}
|
109
|
}
|