silverslice/yii2-queue-failed Manage failed queued jobs in Yii 2

Manage failed queued jobs in Yii 2

  1. Install
  2. Configuration
  3. Usage in console
  4. Notes

When your job fails after max number of attempts in Yii 2, it is removed from a queue as completed. This extension saves failed jobs in database table and helps to view and retry them later.

Install

composer require silverslice/yii2-queue-failed

Apply database migration:

yii migrate --migrationPath=@vendor/silverslice/yii2-queue-failed/src/migrations/

Configuration

Add queueFailed component to the console application config file:

return [
    'components' => [
        'queueFailed' => [
            'class' => silverslice\queueFailed\QueueFailed::class,
        ],
    ],
];

Add queueFailed component to the bootstrap:

return [
    'bootstrap' => [
        'queue', 'queueFailed'
    ],
    // ...
]

Usage in console

Show all failed jobs:
yii queue-failed/list

╔════╤═══════════════════════════╤═════════════════════╗
║ Id │ Class                     │ Failed at           ║
╟────┼───────────────────────────┼─────────────────────╢
║ 1  │ app\models\jobs\FailedJob │ 2022-06-06 06:14:32 ║
╚════╧═══════════════════════════╧═════════════════════╝

Command displays job ID, job class and failure time. The job ID may be used to execute failed job again.

Show detailed information about a job by ID:
yii queue-failed/info ID

Command displays additional information about the job (job payload and error).

Execute a job by ID:
yii queue-failed/exec ID
Execute all jobs:
yii queue-failed/run

Pass --class option to filter jobs by class:

yii queue-failed/run --class='app\models\jobs\FailedJob'
Remove a job by ID:
yii queue-failed/remove ID
Clear all failed jobs:
yii queue-failed/clear

Pass --class option to filter jobs by class.

Notes

Jobs are saved in queue_failed table by default. You can change table name in the config (also you need to change name in migration):

'queueFailed' => [
    'class' => silverslice\queueFailed\QueueFailed::class,
    'tableName' => 'failed_jobs'
],

Extension attaches behavior to save failed jobs to the queue component by default. Change queue component name or add more queue components in the config if you need:

'queueFailed' => [
    'class' => silverslice\queueFailed\QueueFailed::class,
    'queue' => ['queue', 'queueDb'],
],

Extension registers its own console commands based on its component id. You can change it however you like:

'failed' => [
    'class' => silverslice\queueFailed\QueueFailed::class,
    'queue' => ['queue', 'queueDb'],
],

Then use in console:

yii failed/list
0 0
1 follower
23 downloads
Yii Version: 2.0
License: MIT
Category: Others
Developed by: silverslice
Created on: Jun 9, 2022
Last updated: 5 months ago
Packagist Profile
Github Repository

Related Extensions