{"id":15561110,"url":"https://github.com/shipsaas/laravel-priority-queue","last_synced_at":"2025-06-29T09:35:53.246Z","repository":{"id":149991065,"uuid":"620194032","full_name":"shipsaas/laravel-priority-queue","owner":"shipsaas","description":"Priority Queues driver implementation for Laravel. Utilizing DB Driver.","archived":false,"fork":false,"pushed_at":"2024-04-21T11:16:03.000Z","size":144,"stargazers_count":49,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-29T05:03:20.600Z","etag":null,"topics":["laravel","laravel-framework","laravel-package","php","priority-queue","queue"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shipsaas.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-03-28T07:58:43.000Z","updated_at":"2024-08-03T23:31:39.000Z","dependencies_parsed_at":null,"dependency_job_id":"8f241907-b84c-47a2-921a-9b49944b9072","html_url":"https://github.com/shipsaas/laravel-priority-queue","commit_stats":{"total_commits":28,"total_committers":1,"mean_commits":28.0,"dds":0.0,"last_synced_commit":"ff0e05bd692ce7da0c30a5404c5c2b9d20cfaa94"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shipsaas%2Flaravel-priority-queue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shipsaas%2Flaravel-priority-queue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shipsaas%2Flaravel-priority-queue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shipsaas%2Flaravel-priority-queue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shipsaas","download_url":"https://codeload.github.com/shipsaas/laravel-priority-queue/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249199774,"owners_count":21228994,"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":["laravel","laravel-framework","laravel-package","php","priority-queue","queue"],"created_at":"2024-10-02T16:05:34.066Z","updated_at":"2025-04-16T05:27:04.074Z","avatar_url":"https://github.com/shipsaas.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ShipSaaS - Laravel Priority Queue Driver\n\n[![Latest Version](http://poser.pugx.org/shipsaas/laravel-priority-queue/v)](https://packagist.org/packages/shipsaas/laravel-priority-queue)\n[![Total Downloads](http://poser.pugx.org/shipsaas/laravel-priority-queue/downloads)](https://packagist.org/packages/shipsaas/laravel-priority-queue)\n[![codecov](https://codecov.io/gh/shipsaas/laravel-priority-queue/branch/main/graph/badge.svg?token=V3HOOR12HA)](https://codecov.io/gh/shipsaas/laravel-priority-queue)\n[![Build \u0026 Test](https://github.com/shipsaas/laravel-priority-queue/actions/workflows/build.yml/badge.svg)](https://github.com/shipsaas/laravel-priority-queue/actions/workflows/build.yml)\n[![Build \u0026 Test (Laravel 10, 11)](https://github.com/shipsaas/laravel-priority-queue/actions/workflows/build-laravel.yml/badge.svg)](https://github.com/shipsaas/laravel-priority-queue/actions/workflows/build-laravel.yml)\n\nA simple Priority Queue Driver for your Laravel Applications to serve your priority messages and \nmakes users happy 🔋.\n\nWith the famous Repository Pattern of Laravel, Priority Queue Driver is easily get injected into\nLaravel's Lifecycle without any hassle/hurdle.\n\nWe can use built-in artisan command `php artisan queue:work` 😎.\n\n## Supports\n- Laravel 11 (supports by default)\n- Laravel 10 (supports until Laravel drops the bug fixes at [August 6th, 2024](https://laravel.com/docs/11.x/releases))\n- PHP 8.2 \u0026 8.3\n- Any database that Laravel supported.\n\n## Architecture Diagram\n\n![Seth Phat - Laravel Priority Queue](https://i.imgur.com/H8OEMhQ.png)\n\n\n### Why Priority Queue Driver use Database?\n\n- Everybody knows Database (MySQL, PgSQL, etc) 👀.\n- Easy and simple to implement ❤️.\n- Utilize the `ORDER BY` and `INDEX` for fast queue msgs pop process. Faster than any other stuff 🔥.\n- Highest visibility (you can view the jobs and their data in DB) ⭐️.\n- Highest flexibility (you can change the weight directly in DB to unblock important msgs) 💰.\n- No extra tool involved. Just Laravel 🥰.\n\n## Install Laravel Priority Queue\n\n```bash\ncomposer require shipsaas/laravel-priority-queue\n```\n\n### One-Time Setup\n\nExport and run the migration (one-time). We don't load migration by default just in case you want to customize the migration schema 😎.\n\n```bash\nphp artisan vendor:publish --tag=priority-queue-migrations\nphp artisan migrate\n```\n\nOpen `config/queue.php` and add this to the `connections` array:\n\n```php\n'connections' =\u003e [\n    // ... a lot of connections above\n    // then our lovely guy here\n    'database-priority' =\u003e [\n        'driver' =\u003e 'database-priority',\n        'connection' =\u003e 'mysql',\n        'table' =\u003e 'priority_jobs',\n        'queue' =\u003e 'default',\n        'retry_after' =\u003e 90,\n        'after_commit' =\u003e false, // or true, depends on your need\n    ],\n],\n```\n\n## Scale/Reliability Consideration\n\nIt is recommended to use a different database connection (eg `mysql_secondary`) to avoid the worker processes ramming your \nprimary database.\n\n## Usage\n\n### The Job Weight\n\nThe default job weight is **500**.\n\nYou can define a hardcoded weight for your job by using the `$jobWeight` property.\n\n```php\nclass SendEmail implements ShouldQueue\n{\n    public int $jobWeight = 500;\n}\n```\n\nOr if you want to calculate the job weight on runtime, you can use the `UseJobPrioritization` trait:\n\n```php\nuse ShipSaasPriorityQueue\\Traits\\UseJobPrioritization;\n\nclass SendEmail implements ShouldQueue\n{\n    use UseJobPrioritization;\n    \n    public function getJobWeight() : int\n    {\n        return $this-\u003euser-\u003eisUsingProPlan()\n            ? 1000\n            : 500;\n    }\n}\n```\n\n### Dispatch the Queue\n\nYou can use the normal Dispatcher or Queue Facade,... to dispatch the Queue Msgs\n\n### As primary queue\n\n```env\nQUEUE_CONNECTION=database-priority\n```\n\nAnd you're ready to roll.\n\n### As secondary queue\nSpecify the `database-priority` connection when dispatching a queue msg.\n\n```php\n// use Dispatcher\nSendEmail::dispatch($user, $emailContent)\n    -\u003eonConnection('database-priority');\n\n// use Queue Facade\nuse Illuminate\\Support\\Facades\\Queue;\n\nQueue::connection('database-priority')\n    -\u003epush(new SendEmail($user, $emailContent));\n```\n\nI get that you guys might don't want to explicitly put the connection name. Alternatively, you can do this:\n\n```php\nclass SendEmail implements ShouldQueue\n{\n    // first option\n    public $connection = 'database-priority';\n    \n    public function __construct()\n    {\n        // second option\n        $this-\u003eonConnection('database-priority');\n    }\n}\n```\n\n## Run The Queue Worker\n\nNothing different from the Laravel Documentation 😎. Just need to include the `database-priority` driver.\n\n```bash\nphp artisan queue:work database-priority\n\n# Extra win, priority on topic\nphp artisan queue:work database-priority --queue=custom\n```\n\n## Testing\n\nRun `composer test` 😆\n\nAvailable Tests:\n\n- Unit Testing\n- Integration Testing against MySQL and `queue:work` command\n\n## Contributors\n- Seth Phat\n\n## Contributions \u0026 Support the Project\n\nFeel free to submit any PR, please follow PSR-1/PSR-12 coding conventions and unit test is a must.\n\nIf this package is helpful, please give it a ⭐️⭐️⭐️. Thank you!\n\n## License\nMIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshipsaas%2Flaravel-priority-queue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshipsaas%2Flaravel-priority-queue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshipsaas%2Flaravel-priority-queue/lists"}