Extra data in Failed Jobs table

Published 2 months ago by achatzi

Hello everyone.

I have an api that accepts orders and adds them to a queue in order to be transferred to our ERP system (it uses COM objects and it takes a long time, so queues was the best way to go).

When the job fails, it gets transferred to the failed jobs table. My question is if there is a way to add extra data in the failed jobs table, ex the order id. I would like to have a json column in the failed jobs table and add data there.

Is that possible?

Best Answer (As Selected By achatzi)
achatzi

Ok, I managed to find a solution and I am posting it in case someone finds it useful.

I found a package in GitHub to store failed jobs in files (https://github.com/pmatseykanets/file-queue-failer) and I used that for inspiration.

I created a ServiceProvider that overwrites the queue.failer with a class that extends DatabaseFailedJobProvider. In that class I overloaded the log function and everything seems to work.

namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class ExtendedQueueServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap services.
     *
     * @return void
     */
    public function boot()
    {
        // Get a default implementation to trigger a deferred binding
        $_ = $this->app['queue.failer'];
    
        // Swap the implementation
        $this->app->singleton('queue.failer', function ($app) {
            $config = $this->app['config']['queue.failed'];
            
            return new ExtendedDatabaseFailedJobProvider($this->app['db'], $config['database'], $config['table']);
        });
    }
}
achatzi

Ok, I managed to find a solution and I am posting it in case someone finds it useful.

I found a package in GitHub to store failed jobs in files (https://github.com/pmatseykanets/file-queue-failer) and I used that for inspiration.

I created a ServiceProvider that overwrites the queue.failer with a class that extends DatabaseFailedJobProvider. In that class I overloaded the log function and everything seems to work.

namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class ExtendedQueueServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap services.
     *
     * @return void
     */
    public function boot()
    {
        // Get a default implementation to trigger a deferred binding
        $_ = $this->app['queue.failer'];
    
        // Swap the implementation
        $this->app->singleton('queue.failer', function ($app) {
            $config = $this->app['config']['queue.failed'];
            
            return new ExtendedDatabaseFailedJobProvider($this->app['db'], $config['database'], $config['table']);
        });
    }
}

Please sign in or create an account to participate in this conversation.