Skip to content

Commit

Permalink
Properly bury job which is not unserializable (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmenozzi committed Apr 3, 2019
1 parent 2a73a6e commit ad8f91b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/WorkerInstance.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public function boot(): Promise
$payloadData = @unserialize($rawPayload, ['allowed_classes' => false]);
if ($payloadData === false) {
$logContext['raw_payload'] = NonUtf8Cleaner::cleanString($rawPayload);
yield $this->beanstalkClient->bury($jobId);
$this->logger->critical('Cannot unserialize job payload so it has been buried.', $logContext);
continue;
}
Expand Down
10 changes: 10 additions & 0 deletions tests/BeanstalkTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,14 @@ protected function assertReadyJobsCountInTube(int $expectedReadyJobsCount, strin
$stats = $this->pheanstalk->statsTube($tube);
$this->assertEquals($expectedReadyJobsCount, $stats['current-jobs-ready']);
}

/**
* @param int $expectedBuriedJobsCount
* @param string $tube
*/
protected function assertBuriedJobsCountInTube(int $expectedBuriedJobsCount, string $tube)
{
$stats = $this->pheanstalk->statsTube($tube);
$this->assertEquals($expectedBuriedJobsCount, $stats['current-jobs-buried']);
}
}
7 changes: 6 additions & 1 deletion tests/Integration/JobUnserializationErrorHandlingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Amp\Beanstalk\BeanstalkClient;
use Amp\Loop;
use org\bovigo\vfs\vfsStream;
use Webgriffe\Esb\BeanstalkTestCase;
use Webgriffe\Esb\DummyFilesystemWorker;
use Webgriffe\Esb\DummyRepeatProducer;
use Webgriffe\Esb\KernelTestCase;
Expand Down Expand Up @@ -38,7 +39,9 @@ public function testNotUnserializableJobShouldBeHandled()
Loop::delay(
200,
function () {
$beanstalkdClient = new BeanstalkClient('tcp://127.0.0.1:11300?tube=' . self::TUBE);
$beanstalkdClient = new BeanstalkClient(
BeanstalkTestCase::getBeanstalkdConnectionUri() . '?tube=' . self::TUBE
);
yield $beanstalkdClient->put('... not unserializable payload ...');
Loop::delay(
200,
Expand All @@ -52,5 +55,7 @@ function () {
self::$kernel->boot();

$this->assertContains('Cannot unserialize job payload so it has been buried.', $this->dumpLog());
$this->assertReadyJobsCountInTube(0, self::TUBE);
$this->assertBuriedJobsCountInTube(1, self::TUBE);
}
}

0 comments on commit ad8f91b

Please sign in to comment.