18
18
use Illuminate \Contracts \Container \Container ;
19
19
use Illuminate \Contracts \Debug \ExceptionHandler ;
20
20
use SwooleTW \Http \Concerns \InteractsWithWebsocket ;
21
+ use Symfony \Component \Console \Output \ConsoleOutput ;
21
22
use SwooleTW \Http \Concerns \InteractsWithSwooleQueue ;
22
23
use SwooleTW \Http \Concerns \InteractsWithSwooleTable ;
23
24
use Symfony \Component \Debug \Exception \FatalThrowableError ;
@@ -122,7 +123,7 @@ protected function setSwooleServerListeners()
122
123
foreach ($ this ->events as $ event ) {
123
124
$ listener = Str::camel ("on_ $ event " );
124
125
$ callback = method_exists ($ this , $ listener ) ? [$ this , $ listener ] : function () use ($ event ) {
125
- $ this ->container ->make ('events ' )->fire ("swoole. $ event " , func_get_args ());
126
+ $ this ->container ->make ('events ' )->dispatch ("swoole. $ event " , func_get_args ());
126
127
};
127
128
128
129
$ this ->container ->make (Server::class)->on ($ event , $ callback );
@@ -137,7 +138,7 @@ public function onStart()
137
138
$ this ->setProcessName ('master process ' );
138
139
$ this ->createPidFile ();
139
140
140
- $ this ->container ->make ('events ' )->fire ('swoole.start ' , func_get_args ());
141
+ $ this ->container ->make ('events ' )->dispatch ('swoole.start ' , func_get_args ());
141
142
}
142
143
143
144
/**
@@ -148,7 +149,7 @@ public function onStart()
148
149
public function onManagerStart ()
149
150
{
150
151
$ this ->setProcessName ('manager process ' );
151
- $ this ->container ->make ('events ' )->fire ('swoole.managerStart ' , func_get_args ());
152
+ $ this ->container ->make ('events ' )->dispatch ('swoole.managerStart ' , func_get_args ());
152
153
}
153
154
154
155
/**
@@ -162,7 +163,7 @@ public function onWorkerStart($server)
162
163
{
163
164
$ this ->clearCache ();
164
165
165
- $ this ->container ->make ('events ' )->fire ('swoole.workerStart ' , func_get_args ());
166
+ $ this ->container ->make ('events ' )->dispatch ('swoole.workerStart ' , func_get_args ());
166
167
167
168
// don't init laravel app in task workers
168
169
if ($ server ->taskworker ) {
@@ -196,7 +197,7 @@ public function onWorkerStart($server)
196
197
*/
197
198
public function onRequest ($ swooleRequest , $ swooleResponse )
198
199
{
199
- $ this ->app ->make ('events ' )->fire ('swoole.request ' );
200
+ $ this ->app ->make ('events ' )->dispatch ('swoole.request ' );
200
201
201
202
$ this ->resetOnRequest ();
202
203
$ sandbox = $ this ->app ->make (Sandbox::class);
@@ -261,21 +262,15 @@ protected function resetOnRequest()
261
262
*/
262
263
public function onTask ($ server , ...$ args )
263
264
{
264
- if ($ args [0 ] instanceof \Swoole \Server \Task && $ task = array_shift ($ args )) {
265
- list ($ taskId , $ srcWorkerId , $ data ) = [$ task ->id , $ task ->worker_id , $ task ->data ];
266
- } else {
267
- list ($ taskId , $ srcWorkerId , $ data ) = $ args ;
268
- }
269
-
270
- $ this ->container ->make ('events ' )->fire ('swoole.task ' , [$ server , $ taskId , $ srcWorkerId , $ data ]);
265
+ $ this ->container ->make ('events ' )->dispatch ('swoole.task ' , [$ server , $ args ]);
271
266
272
267
try {
273
268
// push websocket message
274
269
if ($ this ->isWebsocketPushPayload ($ data )) {
275
- $ this ->pushMessage ($ server , $ data ['data ' ] ?? [] );
270
+ $ this ->pushMessage ($ server , $ data ['data ' ]);
276
271
// push async task to queue
277
272
} elseif ($ this ->isAsyncTaskPayload ($ data )) {
278
- (new SwooleTaskJob ($ this ->container , $ server , $ data , $ taskId , $ srcWorkerId ))->fire ();
273
+ (new SwooleTaskJob ($ this ->container , $ server , $ data , $ taskId , $ srcWorkerId ))->dispatch ();
279
274
}
280
275
} catch (Throwable $ e ) {
281
276
$ this ->logServerError ($ e );
@@ -292,7 +287,7 @@ public function onTask($server, ...$args)
292
287
public function onFinish ($ server , $ taskId , $ data )
293
288
{
294
289
// task worker callback
295
- $ this ->container ->make ('events ' )->fire ('swoole.finish ' , func_get_args ());
290
+ $ this ->container ->make ('events ' )->dispatch ('swoole.finish ' , func_get_args ());
296
291
297
292
return ;
298
293
}
@@ -426,11 +421,16 @@ protected function isInTesting()
426
421
*/
427
422
public function logServerError (Throwable $ e )
428
423
{
429
- $ this ->container
430
- ->make (ExceptionHandler::class)
431
- ->report (
432
- $ this ->normalizeException ($ e )
433
- );
424
+ if ($ this ->isInTesting ()) {
425
+ return ;
426
+ }
427
+
428
+ $ exception = $ this ->normalizeException ($ e );
429
+ $ this ->container ->make (ConsoleOutput::class)
430
+ ->writeln (sprintf ("<error>%s</error> " , $ exception ));
431
+
432
+ $ this ->container ->make (ExceptionHandler::class)
433
+ ->report ($ exception );
434
434
}
435
435
436
436
/**
0 commit comments