Skip to content

Commit 6118f5b

Browse files
committed
Fix multiple issues
1 parent 7815d48 commit 6118f5b

File tree

5 files changed

+41
-22
lines changed

5 files changed

+41
-22
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
### Fixed
66
* Correct sanitation of job names which previously blocked creation of class based batch jobs
7+
* Fix: Failing jobs throw exception when logging about failing (Array to String Conversion)
8+
* Fix: `BatchQueue` methods `->push` and `->update` now return the `id` of the entry
9+
* Fix: BatchQueue now properly releases failed jobs back into the queue
710

811
## v0.2.0 (2017-04-07)
912

composer.json

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
{
22
"name": "lukewaite/laravel-queue-aws-batch",
33
"description": "Laravel Queue for AWS Batch, enabling users to submit jobs for processing to a Batch queue.",
4-
"keywords": ["laravel", "aws", "batch", "queue"],
4+
"keywords": [
5+
"laravel",
6+
"aws",
7+
"batch",
8+
"queue"
9+
],
510
"license": "MIT",
611
"autoload": {
712
"psr-4": {
@@ -20,6 +25,10 @@
2025
"require-dev": {
2126
"mockery/mockery": "^0.9.6",
2227
"laravel/framework": "~5.1.0",
23-
"phpunit/phpunit": "~4.8"
28+
"phpunit/phpunit": "~4.8",
29+
"squizlabs/php_codesniffer": "^2.8"
30+
},
31+
"scripts": {
32+
"cs": "phpcs --standard=psr2 src/"
2433
}
25-
}
34+
}

src/Console/QueueWorkBatchCommand.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ public function fire()
4949
$this->exceptions->report($e);
5050
}
5151
$this->error($e->getMessage());
52-
$this->error($e->getTrace());
52+
$this->error($e->getTraceAsString());
5353
exit(1);
5454
} catch (\Throwable $e) {
5555
if ($this->exceptions) {
5656
$this->exceptions->report(new FatalThrowableError($e));
5757
}
5858
$this->error($e->getMessage());
59-
$this->error($e->getTrace());
59+
$this->error($e->getTraceAsString());
6060
exit(1);
6161
}
6262
}
@@ -82,7 +82,10 @@ protected function runJob()
8282
// then immediately return back out.
8383
if (!is_null($job)) {
8484
return $this->worker->process(
85-
$this->manager->getName($connectionName), $job, $maxTries, $delay
85+
$this->manager->getName($connectionName),
86+
$job,
87+
$maxTries,
88+
$delay
8689
);
8790
}
8891

src/Queues/BatchQueue.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,20 +76,22 @@ protected function getDisplayName($job)
7676
* @param string $payload
7777
* @param string $jobName
7878
*
79-
* @return mixed
79+
* @return int
8080
*/
8181
protected function pushToBatch($queue, $payload, $jobName)
8282
{
8383
$jobId = $this->pushToDatabase(0, $queue, $payload);
8484

85-
return $this->batch->submitJob([
85+
$this->batch->submitJob([
8686
'jobDefinition' => $this->jobDefinition,
8787
'jobName' => $jobName,
8888
'jobQueue' => $this->getQueue($queue),
8989
'parameters' => [
9090
'jobId' => $jobId,
9191
]
9292
]);
93+
94+
return $jobId;
9395
}
9496

9597
public function getJobById($id, $queue)
@@ -100,7 +102,10 @@ public function getJobById($id, $queue)
100102
}
101103

102104
return new BatchJob(
103-
$this->container, $this, $job, $queue
105+
$this->container,
106+
$this,
107+
$job,
108+
$queue
104109
);
105110
}
106111

@@ -120,19 +125,17 @@ public function release($queue, $job, $delay)
120125
throw new UnsupportedException('The BatchJob does not support releasing back onto the queue with a delay');
121126
}
122127

123-
$attributes = [
124-
'id' => $job->id,
128+
return $this->database->table($this->table)->where('id', $job->id)->update([
125129
'attempts' => $job->attempts,
126130
'reserved' => 0,
127-
'reserved_at' => null,
128-
];
129-
130-
return $this->database->table($this->table)->update($attributes);
131+
'reserved_at' => null
132+
]);
131133
}
132134

133135
public function pop($queue = null)
134136
{
135-
throw new UnsupportedException('The BatchQueue does not support running via a regular worker. Instead, you should use the queue:batch-work command with a job id.');
137+
throw new UnsupportedException('The BatchQueue does not support running via a regular worker. ' .
138+
'Instead, you should use the queue:batch-work command with a job id.');
136139
}
137140

138141
public function bulk($jobs, $data = '', $queue = null)

tests/BatchQueueTest.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ public function tearDown()
1414

1515
public function setUp()
1616
{
17-
/** @var \LukeWaite\LaravelQueueAwsBatch\Queues\BatchQueue $queue */
1817
$this->queue = $this->getMockBuilder('LukeWaite\LaravelQueueAwsBatch\Queues\BatchQueue')->setMethods(null)->setConstructorArgs([
1918
$this->database = m::mock('Illuminate\Database\Connection'),
2019
'table',
@@ -50,7 +49,8 @@ public function testPushProperlyPushesJobOntoDatabase()
5049
$this->assertEquals(['jobId' => 100], $array['parameters']);
5150
});
5251

53-
$this->queue->push('foo', ['data']);
52+
$result = $this->queue->push('foo', ['data']);
53+
$this->assertEquals(100, $result);
5454
}
5555

5656
public function testPushProperlySanitizesJobName()
@@ -81,21 +81,22 @@ public function testGetJobById()
8181

8282
public function testRelease()
8383
{
84-
$this->database->shouldReceive('table')->once()->with('table')->andReturn($query = m::mock('StdClass'));
84+
$this->database->shouldReceive('table')->once()->with('table')->andReturn($table = m::mock('StdClass'));
85+
$table->shouldReceive('where')->once()->with('id', 4)->andReturn($query = m::mock('StdClass'));
8586
$query->shouldReceive('update')->once()->with([
86-
'id' => 4,
8787
'attempts' => 1,
8888
'reserved' => 0,
8989
'reserved_at' => null,
90-
]);
90+
])->andReturn(4);
9191

9292
$job = new \stdClass();
9393
$job->payload = '{"job":"foo","data":["data"]}';
9494
$job->id = 4;
9595
$job->queue = 'default';
9696
$job->attempts = 1;
9797

98-
$this->queue->release('default', $job, 0);
98+
$result = $this->queue->release('default', $job, 0);
99+
$this->assertEquals(4, $result);
99100
}
100101

101102
/**

0 commit comments

Comments
 (0)