作者 邓超

xxx

@@ -10,6 +10,13 @@ class SendJob { @@ -10,6 +10,13 @@ class SendJob {
10 10
11 public $cnum = 0; 11 public $cnum = 0;
12 12
  13 + private $run_timer = 0;
  14 +
  15 + public function __construct()
  16 + {
  17 + $this->run_timer = time();
  18 + }
  19 +
13 /** 20 /**
14 * 是否停止 21 * 是否停止
15 * @return bool 22 * @return bool
@@ -17,6 +24,10 @@ class SendJob { @@ -17,6 +24,10 @@ class SendJob {
17 * @time 2024/4/10 9:12 24 * @time 2024/4/10 9:12
18 */ 25 */
19 private function isStop(){ 26 private function isStop(){
  27 + // 运行超过1天的 停止
  28 + if($this->run_timer < (time()-86400)){
  29 + return true;
  30 + }
20 return redis()->get('send_job_is_stop') == 'stop'; 31 return redis()->get('send_job_is_stop') == 'stop';
21 } 32 }
22 33
@@ -20,10 +20,17 @@ function start(){ @@ -20,10 +20,17 @@ function start(){
20 // 启动业务进程 20 // 启动业务进程
21 $pm->addBatch(WORKER_NUM,function (Process\Pool $pool, int $worker_id){ 21 $pm->addBatch(WORKER_NUM,function (Process\Pool $pool, int $worker_id){
22 _echo("业务进程({$worker_id})启动成功"); 22 _echo("业务进程({$worker_id})启动成功");
  23 + swoole_set_process_name('php-email-sync-list-'.$worker_id);
23 24
  25 + $run_timer = time();
24 // 循环阻塞 26 // 循环阻塞
25 while (true){ 27 while (true){
26 - swoole_set_process_name('php-email-sync-list-'.$worker_id); 28 +
  29 + // 运行超过1天的 停止
  30 + if($run_timer < (time()-86400)){
  31 + break;
  32 + }
  33 +
27 // 需要同步的id 34 // 需要同步的id
28 $id = redis()->lPop('sync_email_lists'); 35 $id = redis()->lPop('sync_email_lists');
29 36
@@ -65,8 +72,13 @@ function start(){ @@ -65,8 +72,13 @@ function start(){
65 $pm->add(function (Process\Pool $pool, int $worker_id){ 72 $pm->add(function (Process\Pool $pool, int $worker_id){
66 _echo("业务进程({$worker_id})启动成功,body"); 73 _echo("业务进程({$worker_id})启动成功,body");
67 swoole_set_process_name('php-email-sync-body-'.$worker_id); 74 swoole_set_process_name('php-email-sync-body-'.$worker_id);
  75 + $run_timer = time();
68 // 循环阻塞 76 // 循环阻塞
69 while (true){ 77 while (true){
  78 + // 运行超过1天的 停止
  79 + if($run_timer < (time()-86400)){
  80 + break;
  81 + }
70 // 需要同步的id 82 // 需要同步的id
71 $id = redis()->lPop('sync_email_body'); 83 $id = redis()->lPop('sync_email_body');
72 84