silverslice/yii2-queue-failed

Manage failed queued jobs in Yii 2

Installs: 25 746

Dependents: 0

Suggesters: 0

Security: 0

Stars: 4

Watchers: 2

Forks: 1

Open Issues: 0

Type:yii2-extension

v1.0.0 2023-06-19 01:51 UTC

This package is auto-updated.

Last update: 2024-10-29 02:23:16 UTC


README

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                     │ Original Job ID │ Failed at           ║
╟────┼───────────────────────────┼─────────────────┼─────────────────────╢
║ 1  │ app\models\jobs\FailedJob │ 123456789       │ 2022-06-06 06:14:32 ║
╚════╧═══════════════════════════╧═════════════════╧═════════════════════╝

Command displays job ID, job class, original job ID and failure time. The 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