Skip to content
This repository was archived by the owner on Mar 9, 2024. It is now read-only.

Commit 47e7868

Browse files
authored
Update AsyncCommand.php
1 parent 4d4981f commit 47e7868

File tree

1 file changed

+12
-28
lines changed

1 file changed

+12
-28
lines changed

Diff for: src/Console/AsyncCommand.php

+12-28
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Barryvdh\Queue\AsyncQueue;
66
use Illuminate\Console\Command;
7+
use Illuminate\Queue\DatabaseQueue;
78
use Illuminate\Queue\Worker;
89
use Illuminate\Queue\WorkerOptions;
910
use Symfony\Component\Console\Input\InputArgument;
@@ -31,21 +32,23 @@ class AsyncCommand extends Command
3132
* @var \Illuminate\Queue\Worker
3233
*/
3334
protected $worker;
35+
3436
/**
3537
* Create a new queue listen command.
3638
*
3739
* @param \Illuminate\Queue\Worker $worker
38-
* @return void
3940
*/
4041
public function __construct(Worker $worker)
4142
{
4243
parent::__construct();
44+
4345
$this->worker = $worker;
4446
}
4547

4648
/**
4749
* Execute the console command.
4850
*
51+
* @param WorkerOptions $options
4952
* @return void
5053
*/
5154
public function fire(WorkerOptions $options)
@@ -57,33 +60,27 @@ public function fire(WorkerOptions $options)
5760
$connection, $id, $options
5861
);
5962
}
60-
61-
63+
6264
/**
6365
* Process the job
64-
*
66+
* @param string $connectionName
67+
* @param integer $id
68+
* @param WorkerOptions $options
6569
*/
6670
protected function processJob($connectionName, $id, $options)
6771
{
6872
$manager = $this->worker->getManager();
73+
74+
/** @var AsyncQueue $connection */
6975
$connection = $manager->connection($connectionName);
7076

7177
$job = $connection->getJobFromId($id);
7278

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(
8181
$manager->getName($connectionName), $job, $options
8282
);
8383
}
84-
85-
return ['job' => null, 'failed' => false];
86-
8784
}
8885

8986
/**
@@ -95,20 +92,7 @@ protected function getArguments()
9592
{
9693
return array(
9794
array('id', InputArgument::REQUIRED, 'The Job ID'),
98-
9995
array('connection', InputArgument::OPTIONAL, 'The name of connection'),
10096
);
10197
}
102-
103-
/**
104-
* Get the console command arguments.
105-
*
106-
* @return array
107-
*/
108-
protected function getOptions()
109-
{
110-
return array(
111-
112-
);
113-
}
11498
}

0 commit comments

Comments
 (0)