4
4
5
5
use Barryvdh \Queue \AsyncQueue ;
6
6
use Illuminate \Console \Command ;
7
+ use Illuminate \Queue \DatabaseQueue ;
7
8
use Illuminate \Queue \Worker ;
8
9
use Illuminate \Queue \WorkerOptions ;
9
10
use Symfony \Component \Console \Input \InputArgument ;
@@ -31,21 +32,23 @@ class AsyncCommand extends Command
31
32
* @var \Illuminate\Queue\Worker
32
33
*/
33
34
protected $ worker ;
35
+
34
36
/**
35
37
* Create a new queue listen command.
36
38
*
37
39
* @param \Illuminate\Queue\Worker $worker
38
- * @return void
39
40
*/
40
41
public function __construct (Worker $ worker )
41
42
{
42
43
parent ::__construct ();
44
+
43
45
$ this ->worker = $ worker ;
44
46
}
45
47
46
48
/**
47
49
* Execute the console command.
48
50
*
51
+ * @param WorkerOptions $options
49
52
* @return void
50
53
*/
51
54
public function fire (WorkerOptions $ options )
@@ -57,33 +60,27 @@ public function fire(WorkerOptions $options)
57
60
$ connection , $ id , $ options
58
61
);
59
62
}
60
-
61
-
63
+
62
64
/**
63
65
* Process the job
64
- *
66
+ * @param string $connectionName
67
+ * @param integer $id
68
+ * @param WorkerOptions $options
65
69
*/
66
70
protected function processJob ($ connectionName , $ id , $ options )
67
71
{
68
72
$ manager = $ this ->worker ->getManager ();
73
+
74
+ /** @var AsyncQueue $connection */
69
75
$ connection = $ manager ->connection ($ connectionName );
70
76
71
77
$ job = $ connection ->getJobFromId ($ id );
72
78
73
- // If we're able to pull a job off of the stack, we will process it and
74
- // then immediately return back out. If there is no job on the queue
75
- // we will "sleep" the worker for the specified number of seconds.
76
- if ( ! is_null ($ job ))
77
- {
78
- $ sleep = max ($ job ->getDatabaseJob ()->available_at - time (), 0 );
79
- sleep ($ sleep );
80
- return $ this ->worker ->process (
79
+ if ( ! is_null ($ job )) {
80
+ $ this ->worker ->process (
81
81
$ manager ->getName ($ connectionName ), $ job , $ options
82
82
);
83
83
}
84
-
85
- return ['job ' => null , 'failed ' => false ];
86
-
87
84
}
88
85
89
86
/**
@@ -95,20 +92,7 @@ protected function getArguments()
95
92
{
96
93
return array (
97
94
array ('id ' , InputArgument::REQUIRED , 'The Job ID ' ),
98
-
99
95
array ('connection ' , InputArgument::OPTIONAL , 'The name of connection ' ),
100
96
);
101
97
}
102
-
103
- /**
104
- * Get the console command arguments.
105
- *
106
- * @return array
107
- */
108
- protected function getOptions ()
109
- {
110
- return array (
111
-
112
- );
113
- }
114
98
}
0 commit comments