therezor / laravel-transactional-jobs

Run Laravel job inside transaction (after transaction is committed, or cancel if rolled back)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Laravel transactional jobs

Problem:

Solution:

By using this package you easily dispatch jobs inside transactions. Cancel job on transaction rollback. Add to queue on transaction committed.

Installation

This package requires PHP 7.1 and Laravel 5.8 or higher. If you are on a PHP version below 7.1 or a Laravel version below 5.8 just use an older version of this package.

  1. Run composer require therezor/laravel-transactional-jobs in your laravel project root folder

  2. Implement TheRezor\TransactionalJobs\Contracts\RunAfterTransaction to jobs that run in the middle of database transactions

<?php

use TheRezor\TransactionalJobs\Contracts\RunAfterTransaction;

class MySuperJob implements ShouldQueue, RunAfterTransaction
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    
    ...
}

About

Run Laravel job inside transaction (after transaction is committed, or cancel if rolled back)

License:MIT License


Languages

Language:PHP 100.0%