Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
"laravel/framework": "~5.1.0",
"phpunit/phpunit": "~4.8"
}
}
}
8 changes: 7 additions & 1 deletion src/Jobs/BatchJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace LukeWaite\LaravelQueueAwsBatch\Jobs;

use Illuminate\Queue\Jobs\DatabaseJob;
use LukeWaite\LaravelQueueAwsBatch\Exceptions\UnsupportedException;

class BatchJob extends DatabaseJob
{
Expand All @@ -30,11 +31,16 @@ class BatchJob extends DatabaseJob
* @param int $delay
*
* @return void
* @throws UnsupportedException
*/
public function release($delay = 0)
{
if ($delay != 0) {
throw new UnsupportedException('The BatchJob does not support releasing back onto the queue with a delay');
}

$this->released = true;

$this->database->release($this->queue, $this->job, $delay);
$this->database->release($this->queue, $this->job, 0);
}
}
59 changes: 59 additions & 0 deletions tests/BatchJobTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

use Mockery as m;
use PHPUnit\Framework\TestCase;

class BatchJobTest extends TestCase
{
public function tearDown()
{
m::close();
}

public function testReleaseDoesntDeleteButDoesUpdate()
{
$job = new \stdClass();
$job->payload = '{"job":"foo","data":["data"]}';
$job->id = 4;
$job->queue = 'default';
$job->attempts = 1;

/** @var \LukeWaite\LaravelQueueAwsBatch\Jobs\BatchJob $batchJob */
$batchJob = $this->getMockBuilder('LukeWaite\LaravelQueueAwsBatch\Jobs\BatchJob')->setMethods(null)->setConstructorArgs([
m::mock('Illuminate\Container\Container'),
$batchQueue = m::mock('LukeWaite\LaravelQueueAwsBatch\Queues\BatchQueue'),
$job,
'default'
])->getMock();

$batchQueue->shouldReceive('release')->once();
$batchQueue->shouldNotReceive('deleteReserved');

$batchJob->release(0);
}

/**
* @expectedException \LukeWaite\LaravelQueueAwsBatch\Exceptions\UnsupportedException
*/
public function testThrowsExceptionOnReleaseWIthDelay()
{
$job = new \stdClass();
$job->payload = '{"job":"foo","data":["data"]}';
$job->id = 4;
$job->queue = 'default';
$job->attempts = 1;

/** @var \LukeWaite\LaravelQueueAwsBatch\Jobs\BatchJob $batchJob */
$batchJob = $this->getMockBuilder('LukeWaite\LaravelQueueAwsBatch\Jobs\BatchJob')->setMethods(null)->setConstructorArgs([
m::mock('Illuminate\Container\Container'),
$batchQueue = m::mock('LukeWaite\LaravelQueueAwsBatch\Queues\BatchQueue'),
$job,
'default'
])->getMock();

$batchQueue->shouldNotReceive('release');
$batchQueue->shouldNotReceive('deleteReserved');

$batchJob->release(10);
}
}
33 changes: 32 additions & 1 deletion tests/BatchQueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function testPushProperlyPushesJobOntoDatabase()
$this->assertEquals('jobdefinition', $array['jobDefinition']);
$this->assertEquals('foo', $array['jobName']);
$this->assertEquals('default', $array['jobQueue']);
$this->assertEquals(['jobId'=>100], $array['parameters']);
$this->assertEquals(['jobId' => 100], $array['parameters']);
});

$queue->push('foo', ['data']);
Expand Down Expand Up @@ -68,6 +68,37 @@ public function testGetJobById()
$queue->getJobById(1, 'default');
}

public function testRelease()
{
/** @var \LukeWaite\LaravelQueueAwsBatch\Queues\BatchQueue $queue */
$queue = $this->getMockBuilder('LukeWaite\LaravelQueueAwsBatch\Queues\BatchQueue')->setMethods(null)->setConstructorArgs([
$database = m::mock('Illuminate\Database\Connection'),
'table',
'default',
'60',
'jobdefinition',
$batch = m::mock('Aws\Batch\BatchClient')
])->getMock();

$database->shouldReceive('table')->once()->with('table')->andReturn($query = m::mock('StdClass'));
$query->shouldReceive('update')->once()->with([
'id' => 4,
'attempts' => 1,
'reserved' => 0,
'reserved_at' => null,
]);

$queue->setContainer(m::mock('Illuminate\Container\Container'));

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

$queue->release('default', $job, 0);
}

/**
* @expectedException LukeWaite\LaravelQueueAwsBatch\Exceptions\UnsupportedException
*/
Expand Down