Skip to content

Commit

Permalink
Merge pull request #20 from lukewaite/queue_release_delay_exception
Browse files Browse the repository at this point in the history
Throw an exception if BatchQueue::release is called with a non-zero
  • Loading branch information
lukewaite authored Apr 7, 2017
2 parents 687285c + f0f333e commit dc97581
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
14 changes: 14 additions & 0 deletions src/Queues/BatchQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,22 @@ public function getJobById($id, $queue)
);
}

/**
* Release the job, without deleting first from the Queue
*
* @param string $queue
* @param \StdClass $job
* @param int $delay
*
* @return int
* @throws UnsupportedException
*/
public function release($queue, $job, $delay)
{
if ($delay != 0) {
throw new UnsupportedException('The BatchJob does not support releasing back onto the queue with a delay');
}

$attributes = [
'id' => $job->id,
'attempts' => $job->attempts,
Expand Down
22 changes: 16 additions & 6 deletions tests/BatchQueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public function setUp()
'jobdefinition',
$this->batch = m::mock('Aws\Batch\BatchClient')
])->getMock();

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

public function testPushProperlyPushesJobOntoDatabase()
Expand Down Expand Up @@ -56,8 +58,6 @@ public function testGetJobById()
$results->shouldReceive('first')->once()->andReturn($queryResult = m::mock('StdClass'));
$queryResult->attempts = 0;

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

$this->queue->getJobById(1, 'default');
}

Expand All @@ -71,8 +71,6 @@ public function testRelease()
'reserved_at' => null,
]);

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

$job = new \stdClass();
$job->payload = '{"job":"foo","data":["data"]}';
$job->id = 4;
Expand All @@ -83,18 +81,30 @@ public function testRelease()
}

/**
* @expectedException LukeWaite\LaravelQueueAwsBatch\Exceptions\UnsupportedException
* @expectedException \LukeWaite\LaravelQueueAwsBatch\Exceptions\UnsupportedException
*/
public function testPopThrowsException()
{
$this->queue->pop('default');
}

/**
* @expectedException LukeWaite\LaravelQueueAwsBatch\Exceptions\UnsupportedException
* @expectedException \LukeWaite\LaravelQueueAwsBatch\Exceptions\UnsupportedException
*/
public function testLaterThrowsException()
{
$this->queue->later(10, 'default');
}

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

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

0 comments on commit dc97581

Please sign in to comment.