diff --git a/src/Illuminate/Queue/Jobs/RedisJob.php b/src/Illuminate/Queue/Jobs/RedisJob.php index 2d59da4bd71c..d8acf3a8c607 100644 --- a/src/Illuminate/Queue/Jobs/RedisJob.php +++ b/src/Illuminate/Queue/Jobs/RedisJob.php @@ -48,6 +48,9 @@ class RedisJob extends Job implements JobContract */ public function __construct(Container $container, RedisQueue $redis, $job, $reserved, $queue) { + // The $job variable is the original job JSON as it existed in the ready queue while + // the $reserved variable is the raw JSON in the reserved queue. The exact format + // of the reserved job is requird in order for us to properly delete its value. $this->job = $job; $this->redis = $redis; $this->queue = $queue; @@ -98,7 +101,7 @@ public function release($delay = 0) */ public function attempts() { - return Arr::get($this->decoded, 'attempts'); + return Arr::get($this->decoded, 'attempts') + 1; } /** diff --git a/src/Illuminate/Queue/RedisQueue.php b/src/Illuminate/Queue/RedisQueue.php index 319794150841..9f4004d460f0 100644 --- a/src/Illuminate/Queue/RedisQueue.php +++ b/src/Illuminate/Queue/RedisQueue.php @@ -130,7 +130,7 @@ protected function createPayloadArray($job, $data = '', $queue = null) { return array_merge(parent::createPayloadArray($job, $data, $queue), [ 'id' => $this->getRandomId(), - 'attempts' => 1, + 'attempts' => 0, ]); } diff --git a/tests/Queue/QueueRedisQueueTest.php b/tests/Queue/QueueRedisQueueTest.php index f8a2f7c19023..aaaabe1c2011 100644 --- a/tests/Queue/QueueRedisQueueTest.php +++ b/tests/Queue/QueueRedisQueueTest.php @@ -14,7 +14,7 @@ public function testPushProperlyPushesJobOntoRedis() $queue = $this->getMockBuilder('Illuminate\Queue\RedisQueue')->setMethods(['getRandomId'])->setConstructorArgs([$redis = m::mock('Illuminate\Contracts\Redis\Factory'), 'default'])->getMock(); $queue->expects($this->once())->method('getRandomId')->will($this->returnValue('foo')); $redis->shouldReceive('connection')->once()->andReturn($redis); - $redis->shouldReceive('rpush')->once()->with('queues:default', json_encode(['job' => 'foo', 'data' => ['data'], 'id' => 'foo', 'attempts' => 1])); + $redis->shouldReceive('rpush')->once()->with('queues:default', json_encode(['job' => 'foo', 'data' => ['data'], 'id' => 'foo', 'attempts' => 0])); $id = $queue->push('foo', ['data']); $this->assertEquals('foo', $id); @@ -30,7 +30,7 @@ public function testDelayedPushProperlyPushesJobOntoRedis() $redis->shouldReceive('zadd')->once()->with( 'queues:default:delayed', 2, - json_encode(['job' => 'foo', 'data' => ['data'], 'id' => 'foo', 'attempts' => 1]) + json_encode(['job' => 'foo', 'data' => ['data'], 'id' => 'foo', 'attempts' => 0]) ); $id = $queue->later(1, 'foo', ['data']); @@ -48,7 +48,7 @@ public function testDelayedPushWithDateTimeProperlyPushesJobOntoRedis() $redis->shouldReceive('zadd')->once()->with( 'queues:default:delayed', 2, - json_encode(['job' => 'foo', 'data' => ['data'], 'id' => 'foo', 'attempts' => 1]) + json_encode(['job' => 'foo', 'data' => ['data'], 'id' => 'foo', 'attempts' => 0]) ); $queue->later($date, 'foo', ['data']); diff --git a/tests/Queue/RedisQueueIntegrationTest.php b/tests/Queue/RedisQueueIntegrationTest.php index 6008936fd6ec..95281c12216a 100644 --- a/tests/Queue/RedisQueueIntegrationTest.php +++ b/tests/Queue/RedisQueueIntegrationTest.php @@ -68,7 +68,7 @@ public function testPopProperlyPopsJobOffOfRedis() $this->assertEquals($job, unserialize(json_decode($redisJob->getRawBody())->data->command)); $this->assertEquals(1, $redisJob->attempts()); $this->assertEquals($job, unserialize(json_decode($redisJob->getReservedJob())->data->command)); - $this->assertEquals(2, json_decode($redisJob->getReservedJob())->attempts); + $this->assertEquals(1, json_decode($redisJob->getReservedJob())->attempts); $this->assertEquals($redisJob->getJobId(), json_decode($redisJob->getReservedJob())->id); // Check reserved queue @@ -216,7 +216,7 @@ public function testRelease() $decoded = json_decode($payload); - $this->assertEquals(2, $decoded->attempts); + $this->assertEquals(1, $decoded->attempts); $this->assertEquals($job, unserialize($decoded->data->command)); //check if the queue has no ready item yet