Skip to content

Commit

Permalink
Make plain string payloads more similar to object based payloads.
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Feb 7, 2017
1 parent 0c1a306 commit bd49288
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
6 changes: 5 additions & 1 deletion src/Illuminate/Queue/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,11 @@ protected function getDisplayName($job)
*/
protected function createStringPayload($job, $data)
{
return ['job' => $job, 'data' => $data];
return [
'displayName' => is_string($job) ? explode('@', $job)[0] : null,
'job' => $job, 'maxTries' => null,
'timeout' => null, 'data' => $data
];
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/Queue/QueueBeanstalkdQueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function testPushProperlyPushesJobOntoBeanstalkd()
$pheanstalk = $queue->getPheanstalk();
$pheanstalk->shouldReceive('useTube')->once()->with('stack')->andReturn($pheanstalk);
$pheanstalk->shouldReceive('useTube')->once()->with('default')->andReturn($pheanstalk);
$pheanstalk->shouldReceive('put')->twice()->with(json_encode(['job' => 'foo', 'data' => ['data']]), 1024, 0, 60);
$pheanstalk->shouldReceive('put')->twice()->with(json_encode(['displayName' => 'foo', 'job' => 'foo', 'maxTries' => null, 'timeout' => null, 'data' => ['data']]), 1024, 0, 60);

$queue->push('foo', ['data'], 'stack');
$queue->push('foo', ['data']);
Expand All @@ -30,7 +30,7 @@ public function testDelayedPushProperlyPushesJobOntoBeanstalkd()
$pheanstalk = $queue->getPheanstalk();
$pheanstalk->shouldReceive('useTube')->once()->with('stack')->andReturn($pheanstalk);
$pheanstalk->shouldReceive('useTube')->once()->with('default')->andReturn($pheanstalk);
$pheanstalk->shouldReceive('put')->twice()->with(json_encode(['job' => 'foo', 'data' => ['data']]), \Pheanstalk\Pheanstalk::DEFAULT_PRIORITY, 5, \Pheanstalk\Pheanstalk::DEFAULT_TTR);
$pheanstalk->shouldReceive('put')->twice()->with(json_encode(['displayName' => 'foo', 'job' => 'foo', 'maxTries' => null, 'timeout' => null, 'data' => ['data']]), \Pheanstalk\Pheanstalk::DEFAULT_PRIORITY, 5, \Pheanstalk\Pheanstalk::DEFAULT_TTR);

$queue->later(5, 'foo', ['data'], 'stack');
$queue->later(5, 'foo', ['data']);
Expand Down
8 changes: 4 additions & 4 deletions tests/Queue/QueueDatabaseQueueUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function testPushProperlyPushesJobOntoDatabase()
$database->shouldReceive('table')->with('table')->andReturn($query = m::mock('StdClass'));
$query->shouldReceive('insertGetId')->once()->andReturnUsing(function ($array) {
$this->assertEquals('default', $array['queue']);
$this->assertEquals(json_encode(['job' => 'foo', 'data' => ['data']]), $array['payload']);
$this->assertEquals(json_encode(['displayName' => 'foo', 'job' => 'foo', 'maxTries' => null, 'timeout' => null, 'data' => ['data']]), $array['payload']);
$this->assertEquals(0, $array['attempts']);
$this->assertNull($array['reserved_at']);
$this->assertInternalType('int', $array['available_at']);
Expand All @@ -41,7 +41,7 @@ public function testDelayedPushProperlyPushesJobOntoDatabase()
$database->shouldReceive('table')->with('table')->andReturn($query = m::mock('StdClass'));
$query->shouldReceive('insertGetId')->once()->andReturnUsing(function ($array) {
$this->assertEquals('default', $array['queue']);
$this->assertEquals(json_encode(['job' => 'foo', 'data' => ['data']]), $array['payload']);
$this->assertEquals(json_encode(['displayName' => 'foo', 'job' => 'foo', 'maxTries' => null, 'timeout' => null, 'data' => ['data']]), $array['payload']);
$this->assertEquals(0, $array['attempts']);
$this->assertNull($array['reserved_at']);
$this->assertInternalType('int', $array['available_at']);
Expand Down Expand Up @@ -91,14 +91,14 @@ public function testBulkBatchPushesOntoDatabase()
$query->shouldReceive('insert')->once()->andReturnUsing(function ($records) {
$this->assertEquals([[
'queue' => 'queue',
'payload' => json_encode(['job' => 'foo', 'data' => ['data']]),
'payload' => json_encode(['displayName' => 'foo', 'job' => 'foo', 'maxTries' => null, 'timeout' => null, 'data' => ['data']]),
'attempts' => 0,
'reserved_at' => null,
'available_at' => 'available',
'created_at' => 'created',
], [
'queue' => 'queue',
'payload' => json_encode(['job' => 'bar', 'data' => ['data']]),
'payload' => json_encode(['displayName' => 'bar', 'job' => 'bar', 'maxTries' => null, 'timeout' => null, 'data' => ['data']]),
'attempts' => 0,
'reserved_at' => null,
'available_at' => 'available',
Expand Down
6 changes: 3 additions & 3 deletions tests/Queue/QueueRedisQueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,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' => 0]));
$redis->shouldReceive('rpush')->once()->with('queues:default', json_encode(['displayName' => 'foo', 'job' => 'foo', 'maxTries' => null, 'timeout' => null, 'data' => ['data'], 'id' => 'foo', 'attempts' => 0]));

$id = $queue->push('foo', ['data']);
$this->assertEquals('foo', $id);
Expand All @@ -33,7 +33,7 @@ public function testDelayedPushProperlyPushesJobOntoRedis()
$redis->shouldReceive('zadd')->once()->with(
'queues:default:delayed',
2,
json_encode(['job' => 'foo', 'data' => ['data'], 'id' => 'foo', 'attempts' => 0])
json_encode(['displayName' => 'foo', 'job' => 'foo', 'maxTries' => null, 'timeout' => null, 'data' => ['data'], 'id' => 'foo', 'attempts' => 0])
);

$id = $queue->later(1, 'foo', ['data']);
Expand All @@ -51,7 +51,7 @@ public function testDelayedPushWithDateTimeProperlyPushesJobOntoRedis()
$redis->shouldReceive('zadd')->once()->with(
'queues:default:delayed',
2,
json_encode(['job' => 'foo', 'data' => ['data'], 'id' => 'foo', 'attempts' => 0])
json_encode(['displayName' => 'foo', 'job' => 'foo', 'maxTries' => null, 'timeout' => null, 'data' => ['data'], 'id' => 'foo', 'attempts' => 0])
);

$queue->later($date, 'foo', ['data']);
Expand Down

0 comments on commit bd49288

Please sign in to comment.