6
6
use Illuminate \Queue \Worker ;
7
7
use Illuminate \Console \Command ;
8
8
use Illuminate \Contracts \Queue \Job ;
9
+ use Illuminate \Queue \Events \JobFailed ;
10
+ use Illuminate \Queue \Events \JobProcessed ;
9
11
use Symfony \Component \Console \Input \InputOption ;
10
12
use Symfony \Component \Console \Input \InputArgument ;
11
13
@@ -56,6 +58,11 @@ public function fire()
56
58
return $ this ->worker ->sleep ($ this ->option ('sleep ' ));
57
59
}
58
60
61
+ // We'll listen to the processed and failed events so we can write information
62
+ // to the console as jobs are processed, which will let the developer watch
63
+ // which jobs are coming through a queue and be informed on its progress.
64
+ $ this ->listenForEvents ();
65
+
59
66
$ queue = $ this ->option ('queue ' );
60
67
61
68
$ delay = $ this ->option ('delay ' );
@@ -67,16 +74,25 @@ public function fire()
67
74
68
75
$ connection = $ this ->argument ('connection ' );
69
76
70
- $ response = $ this ->runWorker (
77
+ $ this ->runWorker (
71
78
$ connection , $ queue , $ delay , $ memory , $ this ->option ('daemon ' )
72
79
);
80
+ }
73
81
74
- // If a job was fired by the worker, we'll write the output out to the console
75
- // so that the developer can watch live while the queue runs in the console
76
- // window, which will also of get logged if stdout is logged out to disk.
77
- if (! is_null ($ response ['job ' ])) {
78
- $ this ->writeOutput ($ response ['job ' ], $ response ['failed ' ]);
79
- }
82
+ /**
83
+ * Listen for the queue events in order to update the console output.
84
+ *
85
+ * @return void
86
+ */
87
+ protected function listenForEvents ()
88
+ {
89
+ $ this ->laravel ['events ' ]->listen (JobProcessed::class, function ($ event ) {
90
+ $ this ->writeOutput ($ event ->job , false );
91
+ });
92
+
93
+ $ this ->laravel ['events ' ]->listen (JobFailed::class, function ($ event ) {
94
+ $ this ->writeOutput ($ event ->job , true );
95
+ });
80
96
}
81
97
82
98
/**
0 commit comments