Skip to content

Commit 7550b7e

Browse files
authored
Merge pull request #29 from lukewaite/fix_batch_queue_retry
fix: Correctly set the queue on construction of a BatchJob
2 parents 16cbdf1 + 2aa745b commit 7550b7e

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
},
2525
"require-dev": {
2626
"mockery/mockery": "^0.9.6",
27-
"laravel/framework": ">5.1.0 <5.4",
27+
"laravel/framework": ">5.1.0 <5.2",
2828
"phpunit/phpunit": "~4.8",
2929
"squizlabs/php_codesniffer": "^2.8",
3030
"scrutinizer/ocular": "^1.3"

src/Console/QueueWorkBatchCommand.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ public function fire()
5353
}
5454
}
5555

56+
/**
57+
* @return array|null
58+
* @throws JobNotFoundException
59+
* @throws UnsupportedException
60+
* @throws \Throwable
61+
*/
5662
protected function runJob()
5763
{
5864
$maxTries = $this->option('tries');
@@ -68,7 +74,7 @@ protected function runJob()
6874
throw new UnsupportedException('queue:work-batch can only be run on batch queues');
6975
}
7076

71-
$job = $connection->getJobById($jobId, $connectionName);
77+
$job = $connection->getJobById($jobId);
7278

7379
// If we're able to pull a job off of the stack, we will process it and
7480
// then immediately return back out.

src/Queues/BatchQueue.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,12 @@ protected function pushToBatch($queue, $payload, $jobName)
9494
return $jobId;
9595
}
9696

97-
public function getJobById($id, $queue)
97+
/**
98+
* @param $id
99+
* @return BatchJob
100+
* @throws JobNotFoundException
101+
*/
102+
public function getJobById($id)
98103
{
99104
$job = $this->database->table($this->table)->where('id', $id)->first();
100105
if (!isset($job)) {
@@ -105,7 +110,7 @@ public function getJobById($id, $queue)
105110
$this->container,
106111
$this,
107112
$job,
108-
$queue
113+
$job->queue
109114
);
110115
}
111116

tests/BatchQueueTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,10 @@ public function testGetJobById()
7575
$query->shouldReceive('where')->once()->with('id', 1)->andReturn($results = m::mock('StdClass'));
7676
$results->shouldReceive('first')->once()->andReturn($queryResult = m::mock('StdClass'));
7777
$queryResult->attempts = 0;
78+
$queryResult->queue = 'defaultQueue';
7879

79-
$this->queue->getJobById(1, 'default');
80+
$job = $this->queue->getJobById(1, 'default');
81+
$this->assertEquals('defaultQueue', $job->getQueue());
8082
}
8183

8284
public function testRelease()

0 commit comments

Comments
 (0)