@@ -70,29 +70,33 @@ public function start(?int $co = null)
70
70
$ task = function () use ($ config ){
71
71
$ queue = $ this ->imiQueue ->getQueue ($ this ->name );
72
72
do {
73
- Event::trigger ('IMI.QUEUE.CONSUMER.BEFORE_POP ' , [
74
- 'queue ' => $ queue ,
75
- ], $ this , ConsumerBeforePopParam::class);
76
- $ message = $ queue ->pop ();
77
- Event::trigger ('IMI.QUEUE.CONSUMER.AFTER_POP ' , [
78
- 'queue ' => $ queue ,
79
- 'message ' => $ message ,
80
- ], $ this , ConsumerAfterPopParam::class);
81
- if (null === $ message )
82
- {
83
- Coroutine::sleep ($ config ->getTimespan ());
84
- }
85
- else
86
- {
87
- Event::trigger ('IMI.QUEUE.CONSUMER.BEFORE_CONSUME ' , [
73
+ try {
74
+ Event::trigger ('IMI.QUEUE.CONSUMER.BEFORE_POP ' , [
88
75
'queue ' => $ queue ,
89
- 'message ' => $ message ,
90
- ], $ this , ConsumerBeforeConsumeParam::class);
91
- $ this ->consume ($ message , $ queue );
92
- Event::trigger ('IMI.QUEUE.CONSUMER.AFTER_CONSUME ' , [
76
+ ], $ this , ConsumerBeforePopParam::class);
77
+ $ message = $ queue ->pop ();
78
+ Event::trigger ('IMI.QUEUE.CONSUMER.AFTER_POP ' , [
93
79
'queue ' => $ queue ,
94
80
'message ' => $ message ,
95
- ], $ this , ConsumerAfterConsumeParam::class);
81
+ ], $ this , ConsumerAfterPopParam::class);
82
+ if (null === $ message )
83
+ {
84
+ Coroutine::sleep ($ config ->getTimespan ());
85
+ }
86
+ else
87
+ {
88
+ Event::trigger ('IMI.QUEUE.CONSUMER.BEFORE_CONSUME ' , [
89
+ 'queue ' => $ queue ,
90
+ 'message ' => $ message ,
91
+ ], $ this , ConsumerBeforeConsumeParam::class);
92
+ $ this ->consume ($ message , $ queue );
93
+ Event::trigger ('IMI.QUEUE.CONSUMER.AFTER_CONSUME ' , [
94
+ 'queue ' => $ queue ,
95
+ 'message ' => $ message ,
96
+ ], $ this , ConsumerAfterConsumeParam::class);
97
+ }
98
+ } catch (\Throwable $ th ) {
99
+ App::getBean ('ErrorLog ' )->onException ($ th );
96
100
}
97
101
} while ($ this ->working );
98
102
};
@@ -107,11 +111,7 @@ public function start(?int $co = null)
107
111
*/
108
112
public function run (ITaskParam $ param )
109
113
{
110
- try {
111
- ($ param ->getData ()['task ' ])();
112
- } catch (\Throwable $ th ) {
113
- App::getBean ('ErrorLog ' )->onException ($ th );
114
- }
114
+ ($ param ->getData ()['task ' ])();
115
115
}
116
116
117
117
});
0 commit comments