|
@@ -4,28 +4,16 @@ |
|
@@ -4,28 +4,16 @@ |
4
|
|
4
|
|
5
|
use Swoole\Process;
|
5
|
use Swoole\Process;
|
6
|
|
6
|
|
|
|
7
|
+include_once __DIR__."/../vendor/autoload.php";
|
7
|
|
8
|
|
8
|
-
|
|
|
9
|
-function start(){
|
|
|
10
|
-
|
|
|
11
|
-// 删除停止运行的值
|
|
|
12
|
-// redis()->delete(SYNC_RUNNING_REDIS_KEY,'email_sync_stop_num');
|
|
|
13
|
-
|
|
|
14
|
- // 进程管理器
|
|
|
15
|
- $pm = new Process\Manager();
|
|
|
16
|
-
|
|
|
17
|
- // 启动业务进程
|
|
|
18
|
- $pm->addBatch(10,function (Process\Pool $pool, int $worker_id){
|
|
|
19
|
-
|
|
|
20
|
- swoole_set_process_name('php-email-sync-list-'.$worker_id);
|
|
|
21
|
-
|
|
|
22
|
- include_once __DIR__."/../vendor/autoload.php";
|
|
|
23
|
- _echo("业务进程({$worker_id})启动成功");
|
|
|
24
|
-
|
9
|
+\Co\run(function (){
|
25
|
$goNum = 0;
|
10
|
$goNum = 0;
|
26
|
- // 循环阻塞
|
|
|
27
|
while (true){
|
11
|
while (true){
|
28
|
|
12
|
|
|
|
13
|
+ if($goNum>=200){
|
|
|
14
|
+ break;
|
|
|
15
|
+ }
|
|
|
16
|
+
|
29
|
// 需要同步的id
|
17
|
// 需要同步的id
|
30
|
$id = redis()->lPop('sync_email_lists');
|
18
|
$id = redis()->lPop('sync_email_lists');
|
31
|
|
19
|
|
|
@@ -53,30 +41,20 @@ function start(){ |
|
@@ -53,30 +41,20 @@ function start(){ |
53
|
});
|
41
|
});
|
54
|
|
42
|
|
55
|
});
|
43
|
});
|
56
|
- while ($goNum == 0){
|
|
|
57
|
- co::sleep(0.5);
|
|
|
58
|
- break;
|
|
|
59
|
- }
|
44
|
+
|
60
|
}
|
45
|
}
|
61
|
}else{
|
46
|
}else{
|
62
|
- co::sleep(1);
|
47
|
+ break;
|
63
|
}
|
48
|
}
|
64
|
- //每次都暂停1秒,防止同一时间启动太多的任务
|
|
|
65
|
- co::sleep(0.5);
|
|
|
66
|
}
|
49
|
}
|
67
|
|
50
|
|
68
|
- },true);
|
|
|
69
|
-
|
|
|
70
|
-
|
|
|
71
|
- // 启动管理器
|
|
|
72
|
- $pm->start();
|
|
|
73
|
-
|
|
|
74
|
-}
|
|
|
75
|
-
|
|
|
76
|
-
|
51
|
+ while ($goNum == 0){
|
|
|
52
|
+ co::sleep(0.5);
|
|
|
53
|
+ break;
|
|
|
54
|
+ }
|
|
|
55
|
+});
|
77
|
|
56
|
|
78
|
|
57
|
|
79
|
-start();
|
|
|
80
|
|
58
|
|
81
|
|
59
|
|
82
|
|
60
|
|