Created
December 1, 2021 13:23
-
-
Save cgsmith/b46009cb479e813e6663a71db3edc553 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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