Skip to content

Commit 7b15ae9

Browse files
committed
优化队列消费者的错误捕获机制
1 parent f15c5ac commit 7b15ae9

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/Service/BaseQueueConsumer.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use Imi\Event\Event;
55
use Swoole\Coroutine;
66
use Imi\Aop\Annotation\Inject;
7+
use Imi\App;
78
use Yurun\Swoole\CoPool\CoPool;
89
use Imi\Queue\Contract\IMessage;
910
use Imi\Queue\Driver\IQueueDriver;
@@ -106,7 +107,11 @@ public function start(?int $co = null)
106107
*/
107108
public function run(ITaskParam $param)
108109
{
109-
($param->getData()['task'])();
110+
try {
111+
($param->getData()['task'])();
112+
} catch(\Throwable $th) {
113+
App::getBean('ErrorLog')->onException($th);
114+
}
110115
}
111116

112117
});

0 commit comments

Comments
 (0)