Skip to content

Instantly share code, notes, and snippets.

@cgsmith
Created December 1, 2021 13:23
Show Gist options
  • Save cgsmith/b46009cb479e813e6663a71db3edc553 to your computer and use it in GitHub Desktop.
Save cgsmith/b46009cb479e813e6663a71db3edc553 to your computer and use it in GitHub Desktop.
<?php
namespace common\behaviors;
use common\models\QueueDead;
use yii\queue\ExecEvent;
use yii\queue\Queue;
class DeadLetterQueue extends \yii\base\Behavior
{
public function events()
{
return array_merge(parent::events(), [
Queue::EVENT_AFTER_ERROR => 'addToDeadLetterQueue',
]);
}
public function addToDeadLetterQueue(ExecEvent $event)
{
if (!$event->retry) {
$model = new QueueDead();
$model->error = $event->error->getMessage();
$model->job = $event->job;
$model->save();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment