{"id":21433285,"url":"https://github.com/jlorente/laravel-transaction-commit-queue","last_synced_at":"2025-07-14T13:30:51.329Z","repository":{"id":44921384,"uuid":"240554236","full_name":"jlorente/laravel-transaction-commit-queue","owner":"jlorente","description":"A Laravel queue connector to process jobs after successful database transactions commits","archived":false,"fork":false,"pushed_at":"2022-01-18T12:18:41.000Z","size":25,"stargazers_count":3,"open_issues_count":1,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-31T12:17:39.807Z","etag":null,"topics":["commit","database","job","laravel","queue","transaction","transactional"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jlorente.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-02-14T16:39:53.000Z","updated_at":"2022-09-24T14:23:33.000Z","dependencies_parsed_at":"2022-09-16T12:41:09.780Z","dependency_job_id":null,"html_url":"https://github.com/jlorente/laravel-transaction-commit-queue","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/jlorente/laravel-transaction-commit-queue","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jlorente%2Flaravel-transaction-commit-queue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jlorente%2Flaravel-transaction-commit-queue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jlorente%2Flaravel-transaction-commit-queue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jlorente%2Flaravel-transaction-commit-queue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jlorente","download_url":"https://codeload.github.com/jlorente/laravel-transaction-commit-queue/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jlorente%2Flaravel-transaction-commit-queue/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265297455,"owners_count":23742586,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["commit","database","job","laravel","queue","transaction","transactional"],"created_at":"2024-11-22T23:27:07.314Z","updated_at":"2025-07-14T13:30:51.034Z","avatar_url":"https://github.com/jlorente.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Laravel Transaction Commit Queue\n================================\n\nA Laravel queue connector to process jobs on successful database transactions \ncommits.\n\nThis connector is very similar to the \"sync\" connector with the difference that \njobs are executed after the database transaction has been committed instead of \ninstantly. \n\nIt is useful for example when sending notifications that cause that other processes \nor third party applications read data from your database. When using database \ntransactions and sending notifications, with another queue connectors there is \nno guarantee that this processes or third parties will find the data as you have \nset it when you sent the notification as the transaction might not has been \ncommitted yet. With this connector, the notifications will be sent on transaction \ncommit event when the database transaction level reaches \"0\".\n\n## Installation\n\nThe preferred way to install this extension is through [composer](http://getcomposer.org/download/).\n\nWith Composer installed, you can then install the extension using the following commands:\n\n```bash\n$ php composer.phar require jlorente/laravel-transaction-commit-queue\n```\n\nor add \n\n```json\n...\n    \"require\": {\n        \"jlorente/laravel-transaction-commit-queue\": \"*\"\n    }\n```\n\nto the ```require``` section of your `composer.json` file.\n\n## Configuration\n\nRegister the ServiceProvider in your config/app.php service provider list.\n\nconfig/app.php\n```php\nreturn [\n    //other stuff\n    'providers' =\u003e [\n        //other stuff\n        Jlorente\\Laravel\\Queue\\TransactionCommit\\TransactionCommitQueueServiceProvider::class,\n    ];\n];\n```\n\nThen add the driver to the application config queue file.\n\nconfig\\queue.php\n```php\nreturn [\n    //other stuff\n    'connections' =\u003e [\n        //other stuff\n        'transaction-commit' =\u003e [\n            'driver' =\u003e 'transaction-commit',\n        ],\n    ],\n];\n```\n\nAnd publish the configuration file.\n\n```bash\n$ php artisan vendor:publish --provider='Jlorente\\Laravel\\Queue\\TransactionCommit\\TransactionCommitQueueServiceProvider'\n```\n\n## Usage\n\nSee the [Laravel documentation](https://laravel.com/docs/master/queues) to learn \nhow to use jobs and queues.\n\nThe basic usage of this queue is like in the following example.\n\n```php\nDB::transaction(function() {\n    // Do something\n\n    dispatch(function() use ($model) {\n        $model-\u003enotify();\n    })-\u003eonConnection('transaction-commit');\n});\n```\n\nHere, the job specified as callback will be delayed until the transaction is \ncommitted.\n\n### Dispatching jobs on nested transactions\n\nYou can dispatch jobs to this queue inside nested transactions and the jobs will \nbe processed after all the transactions have been resolved and the commit has \nbeen perfomed into the database.\n\n```php\nclass ProcessExample {\n    public function run() {\n        DB::transaction(function() {\n            // Do something more\n\n            $this-\u003enestedRun();\n        });\n    }\n\n    public function nestedRun() {\n        DB::transaction(function() {\n            $model = new NotifiableExampleModel();\n\n            // This job will be fired when all the transactions have been commited.\n            dispatch(function() use ($model) {\n                $model-\u003enotify();\n            })-\u003eonConnection('transaction-commit');\n        });\n    }\n}\n\n$command = new ProcessExample();\n$command-\u003erun();\n```\n\nIn this example, the job is dispatched on the transaction created on nestedRun \nmethod, but this method is called by the run method from inside another \ntransaction. The execution of the $model-\u003enotify() callback will be delayed \nuntil all the transactions have been committed.\n\n### Multiple database connections\n\nThe queue driver will use the connection names defined in the database config \nfile in order to create different queues for each connection.\n\nIf you don't specify the queue where to dispatch the job, the default queue will \nbe used and the queue will be processed when the default connection reaches the \ntransaction level of 0.\n\nIf you want to init a transaction in other database connection than the default \none, remember to specify the queue with the connection name on the dispatched \njobs to the transaction-commit-queue like in the following example.\n\n```php\nDB::connection('other-connection')-\u003etransaction(function() {\n    // Do something\n    $model = new NotifiableExampleModel();\n\n    dispatch(function() use ($model) {\n        $model-\u003enotify();\n    })-\u003eonConnection('transaction-commit')-\u003eonQueue('other-connection');\n});\n```\n\n### Testing\n\nIf you use a transaction rollback strategy for testing against the datatabase, you can \nset the environment variable TRANSACTION_COMMIT_DISPATCH_INSTANTLY in order to dispatch \nthe jobs instantly instead of on transaction commit.\n\n## Further Considerations\n\nIf there isn't any open transaction on the database connection, the job with \nbe fired instantly.\n\nIf a transaction is rolled back, all the pending jobs of the rolled back \nconnection will be discarded.\n\nRemember that [notifications](https://laravel.com/docs/master/notifications) can \nalso be enqueued.\n\n## License \n\nCopyright \u0026copy; 2020 José Lorente Martín \u003cjose.lorente.martin@gmail.com\u003e.\n\nLicensed under the BSD 3-Clause License. See LICENSE.txt for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjlorente%2Flaravel-transaction-commit-queue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjlorente%2Flaravel-transaction-commit-queue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjlorente%2Flaravel-transaction-commit-queue/lists"}