From b790f17262734fcb9a648c3c18284e25a3460ca7 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Thu, 24 Dec 2015 09:34:03 +0100 Subject: [PATCH 01/39] Update composer.json --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 4f19113..5784ae1 100644 --- a/composer.json +++ b/composer.json @@ -11,9 +11,9 @@ ], "require": { "php": ">=5.4.0", - "illuminate/support": "5.0.x|5.1.x", - "illuminate/console": "5.0.x|5.1.x", - "symfony/process": "~2.6" + "illuminate/support": "5.0.x|5.1.x|5.2.x", + "illuminate/console": "5.0.x|5.1.x|5.2.x", + "symfony/process": "~2.6|~3.0" }, "autoload": { "psr-4": { From 218e8b04834cdef5f15fd9c5229baa9c7e095652 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Mon, 29 Feb 2016 10:06:07 +0100 Subject: [PATCH 02/39] Remove release Prevent recursive loop with retries. --- src/AsyncQueue.php | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/AsyncQueue.php b/src/AsyncQueue.php index 6043af3..519aa5b 100644 --- a/src/AsyncQueue.php +++ b/src/AsyncQueue.php @@ -86,22 +86,6 @@ public function later($delay, $job, $data = '', $queue = null) return $id; } - /** - * Release a reserved job back onto the queue. - * - * @param string $queue - * @param \StdClass $job - * @param int $delay - * @return void - */ - public function release($queue, $job, $delay) - { - $id = parent::release($queue, $job, $delay); - $this->startProcess($id); - - return $id; - } - protected function pushToDatabase($delay, $queue, $payload, $attempts = 0) { $availableAt = $delay instanceof DateTime ? $delay : Carbon::now()->addSeconds($delay); From 5b425bb2ce55f9ccfc0db4c52424936aed3641a9 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Tue, 23 Aug 2016 21:32:34 +0200 Subject: [PATCH 03/39] Allow L5.3 --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 5784ae1..e461f7a 100644 --- a/composer.json +++ b/composer.json @@ -11,8 +11,8 @@ ], "require": { "php": ">=5.4.0", - "illuminate/support": "5.0.x|5.1.x|5.2.x", - "illuminate/console": "5.0.x|5.1.x|5.2.x", + "illuminate/support": "5.0.x|5.1.x|5.2.x|5.3.x", + "illuminate/console": "5.0.x|5.1.x|5.2.x|5.3.x", "symfony/process": "~2.6|~3.0" }, "autoload": { From 77b8fadfcdacf81d08119366c2bf4a10844796d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Iva=C5=9Fcu?= Date: Fri, 18 Nov 2016 12:32:45 +0200 Subject: [PATCH 04/39] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 263e234..ea6acf5 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,4 @@ -# Laravel 5 Async Queue Driver +# Laravel 5.3 Async Queue Driver ## Push a function/closure to the background. From 21093d1479c2cd4ea6955a6c92bf85f42edf7c2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Iva=C5=9Fcu?= Date: Fri, 18 Nov 2016 12:40:08 +0200 Subject: [PATCH 05/39] Laravel 5.3 WorkerOptions support --- src/Console/AsyncCommand.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Console/AsyncCommand.php b/src/Console/AsyncCommand.php index c6f1ef4..16a3fe8 100644 --- a/src/Console/AsyncCommand.php +++ b/src/Console/AsyncCommand.php @@ -5,6 +5,7 @@ use Barryvdh\Queue\AsyncQueue; use Illuminate\Console\Command; use Illuminate\Queue\Worker; +use Illuminate\Queue\WorkerOptions; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; @@ -47,13 +48,13 @@ public function __construct(Worker $worker) * * @return void */ - public function fire() + public function fire(WorkerOptions $options) { $id = $this->argument('id'); $connection = $this->argument('connection'); $this->processJob( - $connection, $id + $connection, $id, $options ); } @@ -62,7 +63,7 @@ public function fire() * Process the job * */ - protected function processJob($connectionName, $id) + protected function processJob($connectionName, $id, $options) { $manager = $this->worker->getManager(); $connection = $manager->connection($connectionName); @@ -77,7 +78,7 @@ protected function processJob($connectionName, $id) $sleep = max($job->getDatabaseJob()->available_at - time(), 0); sleep($sleep); return $this->worker->process( - $manager->getName($connectionName), $job + $manager->getName($connectionName), $job, $options ); } From dcb052da3a8bfbf6e3c5bc0d5f67cbe0d1a2cebc Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Fri, 18 Nov 2016 12:14:33 +0100 Subject: [PATCH 06/39] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e461f7a..0124ccc 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ }, "extra": { "branch-alias": { - "dev-master": "0.4-dev" + "dev-master": "0.5-dev" } } } From c3ac78713a8e6dbd4af3e3fe694f8930f9c8f5b3 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Fri, 18 Nov 2016 12:14:43 +0100 Subject: [PATCH 07/39] Update composer.json --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 0124ccc..593cedf 100644 --- a/composer.json +++ b/composer.json @@ -11,8 +11,8 @@ ], "require": { "php": ">=5.4.0", - "illuminate/support": "5.0.x|5.1.x|5.2.x|5.3.x", - "illuminate/console": "5.0.x|5.1.x|5.2.x|5.3.x", + "illuminate/support": "5.3.x", + "illuminate/console": "5.3.x", "symfony/process": "~2.6|~3.0" }, "autoload": { From a0b729dcd31c582444e859b9346401fc4b1a99e2 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Fri, 27 Jan 2017 09:33:55 +0100 Subject: [PATCH 08/39] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index ea6acf5..f9bfb34 100644 --- a/readme.md +++ b/readme.md @@ -12,7 +12,7 @@ This package is more usable as an alternative for running incidental tasks in th Require the latest version of this package with Composer - composer require barryvdh/laravel-async-queue:"0.4.x" + composer require barryvdh/laravel-async-queue Add the Service Provider to the providers array in config/app.php From 9fa7673577833f2486678b562fb9708bacd969f0 Mon Sep 17 00:00:00 2001 From: Christopher Moore Date: Sat, 18 Feb 2017 23:32:52 -0700 Subject: [PATCH 09/39] udpate laravel deps (#63) * udpate laravel deps * allow laravel 5.3 * restrict versions --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 593cedf..abc4c8e 100644 --- a/composer.json +++ b/composer.json @@ -11,8 +11,8 @@ ], "require": { "php": ">=5.4.0", - "illuminate/support": "5.3.x", - "illuminate/console": "5.3.x", + "illuminate/support": "5.3.x|5.4.x", + "illuminate/console": "5.3.x|5.4.x", "symfony/process": "~2.6|~3.0" }, "autoload": { From 411d6e3cfd5db1816ec106ae6e672661dbc67465 Mon Sep 17 00:00:00 2001 From: Adrian Crisan Date: Tue, 4 Apr 2017 20:28:46 +0300 Subject: [PATCH 10/39] Make it compatible with Laravel 5.4 (#65) --- readme.md | 9 +++-- src/AsyncQueue.php | 88 +++++++++++++++++++++++----------------------- 2 files changed, 50 insertions(+), 47 deletions(-) diff --git a/readme.md b/readme.md index f9bfb34..9a34316 100644 --- a/readme.md +++ b/readme.md @@ -1,7 +1,10 @@ -# Laravel 5.3 Async Queue Driver +# Laravel 5.4 Async Queue Driver ## Push a function/closure to the background. + +### For Laravel 5.3, check the [0.5 branch](https://github.com/barryvdh/laravel-async-queue/tree/0.4) + Just like the 'sync' driver, this is not a real queue driver. It is always fired immediatly. The only difference is that the closure is sent to the background without waiting for the response. This package is more usable as an alternative for running incidental tasks in the background, without setting up a 'real' queue driver. @@ -31,7 +34,7 @@ You should now be able to use the async driver in config/queue.php. Use the same ... 'async' => array( 'driver' => 'async', - 'table' => 'queue_jobs', + 'table' => 'jobs', 'queue' => 'default', 'expire' => 60, ), @@ -44,7 +47,7 @@ By default, `php` is used as the binary path to PHP. You can change this by addi ... 'async' => array( 'driver' => 'async', - 'table' => 'queue_jobs', + 'table' => 'jobs', 'queue' => 'default', 'expire' => 60, 'binary' => 'php', diff --git a/src/AsyncQueue.php b/src/AsyncQueue.php index 519aa5b..7525f1f 100644 --- a/src/AsyncQueue.php +++ b/src/AsyncQueue.php @@ -1,8 +1,6 @@ startProcess($id); return $id; - } + } /** * Push a new job onto the queue after a delay. @@ -86,40 +84,42 @@ public function later($delay, $job, $data = '', $queue = null) return $id; } - protected function pushToDatabase($delay, $queue, $payload, $attempts = 0) - { - $availableAt = $delay instanceof DateTime ? $delay : Carbon::now()->addSeconds($delay); - - return $this->database->table($this->table)->insertGetId([ - 'queue' => $this->getQueue($queue), - 'payload' => $payload, - 'attempts' => $attempts, - 'reserved' => 1, - 'reserved_at' => $this->getTime(), - 'available_at' => $availableAt->getTimestamp(), - 'created_at' => $this->getTime(), - ]); - } + /** + * Create an array to insert for the given job. + * + * @param string|null $queue + * @param string $payload + * @param int $availableAt + * @param int $attempts + * @return array + */ + protected function buildDatabaseRecord($queue, $payload, $availableAt, $attempts = 0) + { + $record = parent::buildDatabaseRecord($queue, $payload, $availableAt, $attempts); + $record['reserved_at'] = $this->currentTime(); + + return $record; + } /** - * Get the next available job for the queue. - * - * @param string|null $queue - * @return \StdClass|null - */ - public function getJobFromId($id) - { - $job = $this->database->table($this->table) - ->where('id', $id) - ->first(); + * Get the next available job for the queue. + * + * @param string|null $queue + * @return \StdClass|null + */ + public function getJobFromId($id) + { + $job = $this->database->table($this->table) + ->where('id', $id) + ->first(); if($job) { - return new DatabaseJob( - $this->container, $this, $job, $job->queue - ); + return new DatabaseJob( + $this->container, $this, $job, $job->queue + ); } - } + } /** * Make a Process for the Artisan command for the job id. From 3eea853c3f2bf8de5bb48ff681cf468e27078682 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Tue, 4 Apr 2017 19:29:35 +0200 Subject: [PATCH 11/39] Bump to 5.4 --- composer.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index abc4c8e..f6b7f08 100644 --- a/composer.json +++ b/composer.json @@ -11,9 +11,9 @@ ], "require": { "php": ">=5.4.0", - "illuminate/support": "5.3.x|5.4.x", - "illuminate/console": "5.3.x|5.4.x", - "symfony/process": "~2.6|~3.0" + "illuminate/support": "5.4.x", + "illuminate/console": "5.4.x", + "symfony/process": "~3.2" }, "autoload": { "psr-4": { @@ -22,7 +22,7 @@ }, "extra": { "branch-alias": { - "dev-master": "0.5-dev" + "dev-master": "0.6-dev" } } } From 4c0b9cc99880869e2f6baa9c138c191338e1c524 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Tue, 4 Apr 2017 19:29:53 +0200 Subject: [PATCH 12/39] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f6b7f08..92895c3 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ } ], "require": { - "php": ">=5.4.0", + "php": ">=5.6.4", "illuminate/support": "5.4.x", "illuminate/console": "5.4.x", "symfony/process": "~3.2" From fe6941bb7d34d2d8e9289345cc5fce49f05bc956 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Tue, 4 Apr 2017 19:31:43 +0200 Subject: [PATCH 13/39] Update readme.md --- readme.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/readme.md b/readme.md index 9a34316..7a13495 100644 --- a/readme.md +++ b/readme.md @@ -3,7 +3,7 @@ ## Push a function/closure to the background. -### For Laravel 5.3, check the [0.5 branch](https://github.com/barryvdh/laravel-async-queue/tree/0.4) +### For Laravel 5.3, check the [0.5 branch](https://github.com/barryvdh/laravel-async-queue/tree/0.5) Just like the 'sync' driver, this is not a real queue driver. It is always fired immediatly. The only difference is that the closure is sent to the background without waiting for the response. @@ -28,8 +28,6 @@ You need to create the migration table for queues and run it. You should now be able to use the async driver in config/queue.php. Use the same config as for the database, but use async as driver. - 'default' => 'async', - 'connections' => array( ... 'async' => array( @@ -41,7 +39,9 @@ You should now be able to use the async driver in config/queue.php. Use the same ... } -By default, `php` is used as the binary path to PHP. You can change this by adding the `binary` option to the queue config. You can also add extra arguments (for HHVM for example) +Set the default to `async`, either by changing to config or setting `QUEUE_DRIVER` in your `.env` file to `async`. + +> Note: By default, `php` is used as the binary path to PHP. You can change this by adding the `binary` option to the queue config. You can also add extra arguments (for HHVM for example) 'connections' => array( ... From 4d4981f91e36b3917e668eb7dec8f635bd432af5 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Tue, 4 Apr 2017 19:49:17 +0200 Subject: [PATCH 14/39] Fix for 5.4 --- src/AsyncQueue.php | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/AsyncQueue.php b/src/AsyncQueue.php index 7525f1f..2c31a30 100644 --- a/src/AsyncQueue.php +++ b/src/AsyncQueue.php @@ -104,8 +104,8 @@ protected function buildDatabaseRecord($queue, $payload, $availableAt, $attempts /** * Get the next available job for the queue. * - * @param string|null $queue - * @return \StdClass|null + * @param int $id + * @return DatabaseJob */ public function getJobFromId($id) { @@ -113,10 +113,9 @@ public function getJobFromId($id) ->where('id', $id) ->first(); - if($job) { - + if ($job) { return new DatabaseJob( - $this->container, $this, $job, $job->queue + $this->container, $this, $job, $this->connectionName, $job->queue ); } } @@ -124,8 +123,7 @@ public function getJobFromId($id) /** * Make a Process for the Artisan command for the job id. * - * @param int $jobId - * @param int $delay + * @param int $id * * @return void */ @@ -141,8 +139,7 @@ public function startProcess($id) /** * Get the Artisan command as a string for the job id. * - * @param int $jobId - * @param int $delay + * @param int $id * * @return string */ @@ -184,7 +181,4 @@ protected function getBackgroundCommand($cmd) return $cmd.' > /dev/null 2>&1 &'; } } - - - } From 47e78689457d6436bb2ac36e486102982377e536 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Tue, 4 Apr 2017 19:51:08 +0200 Subject: [PATCH 15/39] Update AsyncCommand.php --- src/Console/AsyncCommand.php | 40 +++++++++++------------------------- 1 file changed, 12 insertions(+), 28 deletions(-) diff --git a/src/Console/AsyncCommand.php b/src/Console/AsyncCommand.php index 16a3fe8..05032cb 100644 --- a/src/Console/AsyncCommand.php +++ b/src/Console/AsyncCommand.php @@ -4,6 +4,7 @@ use Barryvdh\Queue\AsyncQueue; use Illuminate\Console\Command; +use Illuminate\Queue\DatabaseQueue; use Illuminate\Queue\Worker; use Illuminate\Queue\WorkerOptions; use Symfony\Component\Console\Input\InputArgument; @@ -31,21 +32,23 @@ class AsyncCommand extends Command * @var \Illuminate\Queue\Worker */ protected $worker; + /** * Create a new queue listen command. * * @param \Illuminate\Queue\Worker $worker - * @return void */ public function __construct(Worker $worker) { parent::__construct(); + $this->worker = $worker; } /** * Execute the console command. * + * @param WorkerOptions $options * @return void */ public function fire(WorkerOptions $options) @@ -57,33 +60,27 @@ public function fire(WorkerOptions $options) $connection, $id, $options ); } - - + /** * Process the job - * + * @param string $connectionName + * @param integer $id + * @param WorkerOptions $options */ protected function processJob($connectionName, $id, $options) { $manager = $this->worker->getManager(); + + /** @var AsyncQueue $connection */ $connection = $manager->connection($connectionName); $job = $connection->getJobFromId($id); - // If we're able to pull a job off of the stack, we will process it and - // then immediately return back out. If there is no job on the queue - // we will "sleep" the worker for the specified number of seconds. - if ( ! is_null($job)) - { - $sleep = max($job->getDatabaseJob()->available_at - time(), 0); - sleep($sleep); - return $this->worker->process( + if ( ! is_null($job)) { + $this->worker->process( $manager->getName($connectionName), $job, $options ); } - - return ['job' => null, 'failed' => false]; - } /** @@ -95,20 +92,7 @@ protected function getArguments() { return array( array('id', InputArgument::REQUIRED, 'The Job ID'), - array('connection', InputArgument::OPTIONAL, 'The name of connection'), ); } - - /** - * Get the console command arguments. - * - * @return array - */ - protected function getOptions() - { - return array( - - ); - } } From c5547dad13622649bf20b09627e5e6c808e40702 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Tue, 4 Apr 2017 19:51:59 +0200 Subject: [PATCH 16/39] Update readme.md --- readme.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/readme.md b/readme.md index 7a13495..4c876ce 100644 --- a/readme.md +++ b/readme.md @@ -56,7 +56,5 @@ Set the default to `async`, either by changing to config or setting `QUEUE_DRIVE ... } -It should work the same as the sync driver, so no need to run a queue listener. Downside is that you cannot actually queue or plan things. -Queue::later() is also fired directly, but just runs `sleep($delay)` in background.. -For more info see http://laravel.com/docs/queues +It should work the same as the sync driver, so no need to run a queue listener. Downside is that you cannot actually queue or plan things. Queue::later() is also fired directly. For more info see http://laravel.com/docs/queues From 04d351995234248d12ea0b099d2f70e0ed5c0d9c Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Thu, 31 Aug 2017 20:37:17 +0200 Subject: [PATCH 17/39] Update composer.json --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 92895c3..718fccd 100644 --- a/composer.json +++ b/composer.json @@ -11,8 +11,8 @@ ], "require": { "php": ">=5.6.4", - "illuminate/support": "5.4.x", - "illuminate/console": "5.4.x", + "illuminate/support": "5.4.x|5.5.x", + "illuminate/console": "5.4.x|5.5.x", "symfony/process": "~3.2" }, "autoload": { From e298cacbe18c28825d81ec13a01cff72ba218b48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Iva=C5=9Fcu?= Date: Fri, 1 Sep 2017 11:50:09 +0300 Subject: [PATCH 18/39] Laravel 5.5 support (#70) * Support Laravel 5.5 Changed fire() to handle() method * Laravel 5.5 Support --- readme.md | 4 +++- src/Console/AsyncCommand.php | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index 4c876ce..5ab1320 100644 --- a/readme.md +++ b/readme.md @@ -1,8 +1,10 @@ -# Laravel 5.4 Async Queue Driver +# Laravel 5.5 Async Queue Driver ## Push a function/closure to the background. +### For Laravel 5.4, check the [0.6 branch](https://github.com/barryvdh/laravel-async-queue/tree/0.6) + ### For Laravel 5.3, check the [0.5 branch](https://github.com/barryvdh/laravel-async-queue/tree/0.5) Just like the 'sync' driver, this is not a real queue driver. It is always fired immediatly. diff --git a/src/Console/AsyncCommand.php b/src/Console/AsyncCommand.php index 05032cb..8604904 100644 --- a/src/Console/AsyncCommand.php +++ b/src/Console/AsyncCommand.php @@ -51,7 +51,7 @@ public function __construct(Worker $worker) * @param WorkerOptions $options * @return void */ - public function fire(WorkerOptions $options) + public function handle(WorkerOptions $options) { $id = $this->argument('id'); $connection = $this->argument('connection'); From 5308988e8537bf1678934a30a5b3f8bf91554d05 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Fri, 1 Sep 2017 10:50:33 +0200 Subject: [PATCH 19/39] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 718fccd..082b7e0 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ }, "extra": { "branch-alias": { - "dev-master": "0.6-dev" + "dev-master": "0.7-dev" } } } From 2ba204a49afa95d76d8dc2ae61606f634e1e0864 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Fri, 1 Sep 2017 11:25:16 +0200 Subject: [PATCH 20/39] Update composer.json --- composer.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/composer.json b/composer.json index 082b7e0..f28005c 100644 --- a/composer.json +++ b/composer.json @@ -23,6 +23,11 @@ "extra": { "branch-alias": { "dev-master": "0.7-dev" + }, + "laravel": { + "providers": [ + "Barryvdh\\Queue\\AsyncServiceProvider" + ] } } } From b849a4b1f650eca5101bb2d14282400cf7d4eb9f Mon Sep 17 00:00:00 2001 From: Lachlan Heywood Date: Thu, 7 Sep 2017 15:04:44 -0400 Subject: [PATCH 21/39] Update readme.md (#72) Update links to old branches --- readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index 5ab1320..c07ae6b 100644 --- a/readme.md +++ b/readme.md @@ -3,9 +3,9 @@ ## Push a function/closure to the background. -### For Laravel 5.4, check the [0.6 branch](https://github.com/barryvdh/laravel-async-queue/tree/0.6) +### For Laravel 5.4, check the [0.6 branch](https://github.com/barryvdh/laravel-async-queue/tree/v0.6.0) -### For Laravel 5.3, check the [0.5 branch](https://github.com/barryvdh/laravel-async-queue/tree/0.5) +### For Laravel 5.3, check the [0.5 branch](https://github.com/barryvdh/laravel-async-queue/tree/v0.5.0) Just like the 'sync' driver, this is not a real queue driver. It is always fired immediatly. The only difference is that the closure is sent to the background without waiting for the response. From 638574bceafaced815b8501e47f626d9d8dc34e9 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Mon, 30 Apr 2018 15:16:35 +0200 Subject: [PATCH 22/39] Update composer.json --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index f28005c..d794a28 100644 --- a/composer.json +++ b/composer.json @@ -11,9 +11,9 @@ ], "require": { "php": ">=5.6.4", - "illuminate/support": "5.4.x|5.5.x", - "illuminate/console": "5.4.x|5.5.x", - "symfony/process": "~3.2" + "illuminate/support": "5.4.x|5.5.x|5.6.x", + "illuminate/console": "5.4.x|5.5.x|5.6.x", + "symfony/process": "^3.2|^4" }, "autoload": { "psr-4": { From a331bd234d2f7f9ce8059cfeb48e6941e01012f9 Mon Sep 17 00:00:00 2001 From: Farid Inawan Date: Wed, 13 Jun 2018 15:17:52 +0700 Subject: [PATCH 23/39] Job should be marked as resolved and attemps should be incremented (#79) --- src/AsyncQueue.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/AsyncQueue.php b/src/AsyncQueue.php index 2c31a30..3ed5b66 100644 --- a/src/AsyncQueue.php +++ b/src/AsyncQueue.php @@ -5,6 +5,7 @@ use Illuminate\Queue\DatabaseQueue; use Illuminate\Queue\Jobs\DatabaseJob; use Symfony\Component\Process\Process; +use Illuminate\Queue\Jobs\DatabaseJobRecord; class AsyncQueue extends DatabaseQueue { @@ -114,6 +115,7 @@ public function getJobFromId($id) ->first(); if ($job) { + $job = $this->markJobAsReserved(new DatabaseJobRecord((object) $job)); return new DatabaseJob( $this->container, $this, $job, $this->connectionName, $job->queue ); From a7c2b41991c654b00dd5df2546819f891545a4b6 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Fri, 31 Aug 2018 15:30:59 +0200 Subject: [PATCH 24/39] Update composer.json --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index d794a28..70627cb 100644 --- a/composer.json +++ b/composer.json @@ -10,9 +10,9 @@ } ], "require": { - "php": ">=5.6.4", - "illuminate/support": "5.4.x|5.5.x|5.6.x", - "illuminate/console": "5.4.x|5.5.x|5.6.x", + "php": ">=7", + "illuminate/support": "5.5.x|5.6.x|5.7.x", + "illuminate/console": "5.5.x|5.6.x|5.7.x", "symfony/process": "^3.2|^4" }, "autoload": { From 875ecae286652a7d550679bf332379a99bbc0a46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Iva=C5=9Fcu?= Date: Sat, 2 Mar 2019 16:13:35 +0200 Subject: [PATCH 25/39] Laravel 5.8 support (#82) * Laravel 5.8 support * Update readme.md --- composer.json | 4 ++-- readme.md | 2 +- src/AsyncQueue.php | 15 ++++++++------- src/AsyncServiceProvider.php | 2 +- src/Connectors/AsyncConnector.php | 11 ++++++----- src/Console/AsyncCommand.php | 13 +++++++------ 6 files changed, 25 insertions(+), 22 deletions(-) diff --git a/composer.json b/composer.json index 70627cb..21bf978 100644 --- a/composer.json +++ b/composer.json @@ -11,8 +11,8 @@ ], "require": { "php": ">=7", - "illuminate/support": "5.5.x|5.6.x|5.7.x", - "illuminate/console": "5.5.x|5.6.x|5.7.x", + "illuminate/support": "5.5.x|5.6.x|5.7.x|5.8.x", + "illuminate/console": "5.5.x|5.6.x|5.7.x|5.8.x", "symfony/process": "^3.2|^4" }, "autoload": { diff --git a/readme.md b/readme.md index c07ae6b..4aba467 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,4 @@ -# Laravel 5.5 Async Queue Driver +# Laravel 5 Async Queue Driver ## Push a function/closure to the background. diff --git a/src/AsyncQueue.php b/src/AsyncQueue.php index 3ed5b66..a59bfed 100644 --- a/src/AsyncQueue.php +++ b/src/AsyncQueue.php @@ -59,7 +59,7 @@ public function push($job, $data = '', $queue = null) * @param array $options * @return mixed */ - public function pushRaw($payload, $queue = null, array $options = array()) + public function pushRaw($payload, $queue = null, array $options = []) { $id = parent::pushRaw($payload, $queue, $options); $this->startProcess($id); @@ -164,23 +164,24 @@ protected function getCommand($id) protected function getPhpBinary() { $path = $this->binary; - if (!defined('PHP_WINDOWS_VERSION_BUILD')) { + if ( ! defined('PHP_WINDOWS_VERSION_BUILD')) { $path = escapeshellarg($path); } $args = $this->binaryArgs; - if(is_array($args)){ + if (is_array($args)) { $args = implode(' ', $args); } - return trim($path.' '.$args); + + return trim($path . ' ' . $args); } protected function getBackgroundCommand($cmd) { if (defined('PHP_WINDOWS_VERSION_BUILD')) { - return 'start /B '.$cmd.' > NUL'; - } else { - return $cmd.' > /dev/null 2>&1 &'; + return 'start /B ' . $cmd . ' > NUL'; } + + return $cmd . ' > /dev/null 2>&1 &'; } } diff --git a/src/AsyncServiceProvider.php b/src/AsyncServiceProvider.php index af297b6..fab4b14 100644 --- a/src/AsyncServiceProvider.php +++ b/src/AsyncServiceProvider.php @@ -71,6 +71,6 @@ protected function registerAsyncConnector($manager) */ public function provides() { - return array('command.queue.async'); + return ['command.queue.async']; } } diff --git a/src/Connectors/AsyncConnector.php b/src/Connectors/AsyncConnector.php index 00e23c1..e725797 100644 --- a/src/Connectors/AsyncConnector.php +++ b/src/Connectors/AsyncConnector.php @@ -4,6 +4,7 @@ use Barryvdh\Queue\AsyncQueue; use Illuminate\Queue\Connectors\DatabaseConnector; +use Illuminate\Support\Arr; class AsyncConnector extends DatabaseConnector { @@ -18,13 +19,13 @@ class AsyncConnector extends DatabaseConnector public function connect(array $config) { return new AsyncQueue( - $this->connections->connection(array_get($config, 'connection')), + $this->connections->connection(Arr::get($config, 'connection')), $config['table'], $config['queue'], - array_get($config, 'expire', 60), - array_get($config, 'binary', 'php'), - array_get($config, 'binary_args', ''), - array_get($config, 'connection_name', '') + Arr::get($config, 'expire', 60), + Arr::get($config, 'binary', 'php'), + Arr::get($config, 'binary_args', ''), + Arr::get($config, 'connection_name', '') ); } } diff --git a/src/Console/AsyncCommand.php b/src/Console/AsyncCommand.php index 8604904..1950e98 100644 --- a/src/Console/AsyncCommand.php +++ b/src/Console/AsyncCommand.php @@ -4,11 +4,9 @@ use Barryvdh\Queue\AsyncQueue; use Illuminate\Console\Command; -use Illuminate\Queue\DatabaseQueue; use Illuminate\Queue\Worker; use Illuminate\Queue\WorkerOptions; use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputOption; class AsyncCommand extends Command { @@ -63,9 +61,12 @@ public function handle(WorkerOptions $options) /** * Process the job + * * @param string $connectionName * @param integer $id * @param WorkerOptions $options + * + * @throws \Throwable */ protected function processJob($connectionName, $id, $options) { @@ -90,9 +91,9 @@ protected function processJob($connectionName, $id, $options) */ protected function getArguments() { - return array( - array('id', InputArgument::REQUIRED, 'The Job ID'), - array('connection', InputArgument::OPTIONAL, 'The name of connection'), - ); + return [ + ['id', InputArgument::REQUIRED, 'The Job ID'], + ['connection', InputArgument::OPTIONAL, 'The name of connection'], + ]; } } From e8d696295d2ced1df31f7f797d1a6f1ddea71bb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Iva=C5=9Fcu?= Date: Mon, 9 Sep 2019 13:03:36 +0300 Subject: [PATCH 26/39] Laravel 6.0 Compatibility (#86) * Laravel 6.0 Compatibility * Update composer.json --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 21bf978..1763253 100644 --- a/composer.json +++ b/composer.json @@ -11,8 +11,8 @@ ], "require": { "php": ">=7", - "illuminate/support": "5.5.x|5.6.x|5.7.x|5.8.x", - "illuminate/console": "5.5.x|5.6.x|5.7.x|5.8.x", + "illuminate/support": "^5.5|^6", + "illuminate/console": "^5.5|^6", "symfony/process": "^3.2|^4" }, "autoload": { From 30868e3bf87c769010d8d4d06f1569b518d773b0 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Tue, 25 Feb 2020 21:53:44 +0100 Subject: [PATCH 27/39] Update composer.json --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 1763253..263f500 100644 --- a/composer.json +++ b/composer.json @@ -11,9 +11,9 @@ ], "require": { "php": ">=7", - "illuminate/support": "^5.5|^6", - "illuminate/console": "^5.5|^6", - "symfony/process": "^3.2|^4" + "illuminate/support": "^5.5|^6|^7", + "illuminate/console": "^5.5|^6|^7", + "symfony/process": "^3.2|^4|^5" }, "autoload": { "psr-4": { From 2ec069792a1005e150647fcaaed271968ca5ea66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Iva=C5=9Fcu?= Date: Sat, 12 Sep 2020 19:37:00 +0300 Subject: [PATCH 28/39] Laravel 8 support (#94) * Laravel 8 support * Update composer.json Co-authored-by: Barry vd. Heuvel --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 263f500..25cc511 100644 --- a/composer.json +++ b/composer.json @@ -11,8 +11,8 @@ ], "require": { "php": ">=7", - "illuminate/support": "^5.5|^6|^7", - "illuminate/console": "^5.5|^6|^7", + "illuminate/support": "^5.5|^6|^7|^8", + "illuminate/console": "^5.5|^6|^7|^8", "symfony/process": "^3.2|^4|^5" }, "autoload": { From 39f044e11ed9af0afed4df8ed1fbd8706dabe596 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Iva=C5=9Fcu?= Date: Mon, 17 May 2021 11:23:42 +0300 Subject: [PATCH 29/39] Process needs command to be array (#95) --- src/AsyncQueue.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AsyncQueue.php b/src/AsyncQueue.php index a59bfed..3db92f8 100644 --- a/src/AsyncQueue.php +++ b/src/AsyncQueue.php @@ -134,7 +134,7 @@ public function startProcess($id) $command = $this->getCommand($id); $cwd = base_path(); - $process = new Process($command, $cwd); + $process = new Process([$command], $cwd); $process->run(); } From f2ac186f7afbfe5ef22445bc4dd9d036907c35e4 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Mon, 17 May 2021 10:26:03 +0200 Subject: [PATCH 30/39] Update composer.json --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 25cc511..98717fb 100644 --- a/composer.json +++ b/composer.json @@ -11,9 +11,9 @@ ], "require": { "php": ">=7", - "illuminate/support": "^5.5|^6|^7|^8", - "illuminate/console": "^5.5|^6|^7|^8", - "symfony/process": "^3.2|^4|^5" + "illuminate/support": "^6|^7|^8", + "illuminate/console": "^6|^7|^8", + "symfony/process": "^4|^5" }, "autoload": { "psr-4": { From 1b40f1177dbf322dcf0ccae0f93e555d610971c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Iva=C5=9Fcu?= Date: Wed, 9 Feb 2022 15:35:20 +0200 Subject: [PATCH 31/39] Laravel 9 support (#99) --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 98717fb..b6822ce 100644 --- a/composer.json +++ b/composer.json @@ -11,9 +11,9 @@ ], "require": { "php": ">=7", - "illuminate/support": "^6|^7|^8", - "illuminate/console": "^6|^7|^8", - "symfony/process": "^4|^5" + "illuminate/support": "^6|^7|^8|^9", + "illuminate/console": "^6|^7|^8|^9", + "symfony/process": "^4|^5|^6" }, "autoload": { "psr-4": { From 2a6a11a0104184374129189d93c6305482e27b89 Mon Sep 17 00:00:00 2001 From: Laravel Shift Date: Sun, 5 Feb 2023 10:01:47 -0500 Subject: [PATCH 32/39] Bump dependencies for Laravel 10 (#100) --- composer.json | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index b6822ce..568329d 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,12 @@ { "name": "barryvdh/laravel-async-queue", "description": "Async Queue Driver for Laravel (Push to background)", - "keywords": ["laravel", "queue", "async", "background"], + "keywords": [ + "laravel", + "queue", + "async", + "background" + ], "license": "MIT", "authors": [ { @@ -11,8 +16,8 @@ ], "require": { "php": ">=7", - "illuminate/support": "^6|^7|^8|^9", - "illuminate/console": "^6|^7|^8|^9", + "illuminate/support": "^6|^7|^8|^9|^10.0", + "illuminate/console": "^6|^7|^8|^9|^10.0", "symfony/process": "^4|^5|^6" }, "autoload": { From 58583499e99c643ad7aa824b9e4afcf2104dcd41 Mon Sep 17 00:00:00 2001 From: Laravel Shift Date: Sat, 2 Mar 2024 05:11:09 -0500 Subject: [PATCH 33/39] Bump dependencies for Laravel 11 (#102) --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 568329d..55d78a0 100644 --- a/composer.json +++ b/composer.json @@ -16,9 +16,9 @@ ], "require": { "php": ">=7", - "illuminate/support": "^6|^7|^8|^9|^10.0", - "illuminate/console": "^6|^7|^8|^9|^10.0", - "symfony/process": "^4|^5|^6" + "illuminate/support": "^6|^7|^8|^9|^10.0|^11.0", + "illuminate/console": "^6|^7|^8|^9|^10.0|^11.0", + "symfony/process": "^4|^5|^6|^7.0" }, "autoload": { "psr-4": { From 20c92d5299546002c5e34587f244d78f92c9cc62 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Mon, 3 Nov 2025 12:05:43 +0100 Subject: [PATCH 34/39] Use Laravel Concurrency with SyncDriver instead of DatabaseDriver (#103) * Update package requirements for Laravel Concurrency * Use Laravel Concurrency driver --- composer.json | 7 +- readme.md | 39 +------ src/AsyncQueue.php | 183 ++---------------------------- src/AsyncServiceProvider.php | 47 +------- src/Connectors/AsyncConnector.php | 22 +--- src/Console/AsyncCommand.php | 99 ---------------- 6 files changed, 20 insertions(+), 377 deletions(-) delete mode 100644 src/Console/AsyncCommand.php diff --git a/composer.json b/composer.json index 55d78a0..2c07a27 100644 --- a/composer.json +++ b/composer.json @@ -16,9 +16,8 @@ ], "require": { "php": ">=7", - "illuminate/support": "^6|^7|^8|^9|^10.0|^11.0", - "illuminate/console": "^6|^7|^8|^9|^10.0|^11.0", - "symfony/process": "^4|^5|^6|^7.0" + "illuminate/support": "^11.0|^12.0", + "illuminate/queue": "^11.0|^12.0" }, "autoload": { "psr-4": { @@ -27,7 +26,7 @@ }, "extra": { "branch-alias": { - "dev-master": "0.7-dev" + "dev-master": "0.8-dev" }, "laravel": { "providers": [ diff --git a/readme.md b/readme.md index 4aba467..e059221 100644 --- a/readme.md +++ b/readme.md @@ -1,17 +1,11 @@ -# Laravel 5 Async Queue Driver +# Laravel Async Queue Driver ## Push a function/closure to the background. - -### For Laravel 5.4, check the [0.6 branch](https://github.com/barryvdh/laravel-async-queue/tree/v0.6.0) - -### For Laravel 5.3, check the [0.5 branch](https://github.com/barryvdh/laravel-async-queue/tree/v0.5.0) - -Just like the 'sync' driver, this is not a real queue driver. It is always fired immediatly. +Just like the 'sync' or 'deferred' connection, this is not a real queue. It is always fired immediately. The only difference is that the closure is sent to the background without waiting for the response. This package is more usable as an alternative for running incidental tasks in the background, without setting up a 'real' queue driver. - -> **Note:** This is using the DatabaseQueue, so make sure you set that up first, including migrations. +It is similar to the 'deferred' connection, but it runs in a background process, so might be more suitable for long running tasks. ### Install @@ -19,44 +13,17 @@ Require the latest version of this package with Composer composer require barryvdh/laravel-async-queue -Add the Service Provider to the providers array in config/app.php - - Barryvdh\Queue\AsyncServiceProvider::class, - -You need to create the migration table for queues and run it. - - $ php artisan queue:table - $ php artisan migrate - You should now be able to use the async driver in config/queue.php. Use the same config as for the database, but use async as driver. 'connections' => array( ... 'async' => array( 'driver' => 'async', - 'table' => 'jobs', - 'queue' => 'default', - 'expire' => 60, ), ... } Set the default to `async`, either by changing to config or setting `QUEUE_DRIVER` in your `.env` file to `async`. -> Note: By default, `php` is used as the binary path to PHP. You can change this by adding the `binary` option to the queue config. You can also add extra arguments (for HHVM for example) - - 'connections' => array( - ... - 'async' => array( - 'driver' => 'async', - 'table' => 'jobs', - 'queue' => 'default', - 'expire' => 60, - 'binary' => 'php', - 'binary_args' => '', - ), - ... - } - It should work the same as the sync driver, so no need to run a queue listener. Downside is that you cannot actually queue or plan things. Queue::later() is also fired directly. For more info see http://laravel.com/docs/queues diff --git a/src/AsyncQueue.php b/src/AsyncQueue.php index 3db92f8..a30db73 100644 --- a/src/AsyncQueue.php +++ b/src/AsyncQueue.php @@ -1,187 +1,18 @@ binary = $binary; - $this->binaryArgs = $binaryArgs; - $this->connectionName = $connectionName; - } - - /** - * Push a new job onto the queue. - * - * @param string $job - * @param mixed $data - * @param string|null $queue - * - * @return int + * {@inheritdoc} */ public function push($job, $data = '', $queue = null) { - $id = parent::push($job, $data, $queue); - $this->startProcess($id); - - return $id; - } - - /** - * Push a raw payload onto the queue. - * - * @param string $payload - * @param string $queue - * @param array $options - * @return mixed - */ - public function pushRaw($payload, $queue = null, array $options = []) - { - $id = parent::pushRaw($payload, $queue, $options); - $this->startProcess($id); - - return $id; - } - - /** - * Push a new job onto the queue after a delay. - * - * @param \DateTime|int $delay - * @param string $job - * @param mixed $data - * @param string|null $queue - * - * @return int - */ - public function later($delay, $job, $data = '', $queue = null) - { - $id = parent::later($delay, $job, $data, $queue); - $this->startProcess($id); - - return $id; - } - - /** - * Create an array to insert for the given job. - * - * @param string|null $queue - * @param string $payload - * @param int $availableAt - * @param int $attempts - * @return array - */ - protected function buildDatabaseRecord($queue, $payload, $availableAt, $attempts = 0) - { - $record = parent::buildDatabaseRecord($queue, $payload, $availableAt, $attempts); - $record['reserved_at'] = $this->currentTime(); - - return $record; - } - - /** - * Get the next available job for the queue. - * - * @param int $id - * @return DatabaseJob - */ - public function getJobFromId($id) - { - $job = $this->database->table($this->table) - ->where('id', $id) - ->first(); - - if ($job) { - $job = $this->markJobAsReserved(new DatabaseJobRecord((object) $job)); - return new DatabaseJob( - $this->container, $this, $job, $this->connectionName, $job->queue - ); - } - } - - /** - * Make a Process for the Artisan command for the job id. - * - * @param int $id - * - * @return void - */ - public function startProcess($id) - { - $command = $this->getCommand($id); - $cwd = base_path(); - - $process = new Process([$command], $cwd); - $process->run(); - } - - /** - * Get the Artisan command as a string for the job id. - * - * @param int $id - * - * @return string - */ - protected function getCommand($id) - { - $connection = $this->connectionName; - $cmd = '%s artisan queue:async %d %s'; - $cmd = $this->getBackgroundCommand($cmd); - - $binary = $this->getPhpBinary(); - - return sprintf($cmd, $binary, $id, $connection); - } - - /** - * Get the escaped PHP Binary from the configuration - * - * @return string - */ - protected function getPhpBinary() - { - $path = $this->binary; - if ( ! defined('PHP_WINDOWS_VERSION_BUILD')) { - $path = escapeshellarg($path); - } - - $args = $this->binaryArgs; - if (is_array($args)) { - $args = implode(' ', $args); - } - - return trim($path . ' ' . $args); - } - - protected function getBackgroundCommand($cmd) - { - if (defined('PHP_WINDOWS_VERSION_BUILD')) { - return 'start /B ' . $cmd . ' > NUL'; - } - - return $cmd . ' > /dev/null 2>&1 &'; + Concurrency::driver('process') + ->defer(fn () => Queue::connection('sync')->push($job, $data, $queue)); } } diff --git a/src/AsyncServiceProvider.php b/src/AsyncServiceProvider.php index fab4b14..5fb86a8 100644 --- a/src/AsyncServiceProvider.php +++ b/src/AsyncServiceProvider.php @@ -4,17 +4,11 @@ use Barryvdh\Queue\Connectors\AsyncConnector; use Barryvdh\Queue\Console\AsyncCommand; +use Illuminate\Contracts\Support\DeferrableProvider; use Illuminate\Support\ServiceProvider; -class AsyncServiceProvider extends ServiceProvider +class AsyncServiceProvider extends ServiceProvider implements DeferrableProvider { - /** - * Indicates if loading of the provider is deferred. - * - * @var bool - */ - protected $defer = false; - /** * Add the connector to the queue drivers. * @@ -23,31 +17,6 @@ class AsyncServiceProvider extends ServiceProvider public function boot() { $this->registerAsyncConnector($this->app['queue']); - - $this->commands('command.queue.async'); - } - - /** - * Register the service provider. - * - * @return void - */ - public function register() - { - $this->registerAsyncCommand(); - } - - /** - * Register the queue listener console command. - * - * - * @return void - */ - protected function registerAsyncCommand() - { - $this->app->singleton('command.queue.async', function () { - return new AsyncCommand($this->app['queue.worker']); - }); } /** @@ -60,17 +29,7 @@ protected function registerAsyncCommand() protected function registerAsyncConnector($manager) { $manager->addConnector('async', function () { - return new AsyncConnector($this->app['db']); + return new AsyncConnector; }); } - - /** - * Get the services provided by the provider. - * - * @return array - */ - public function provides() - { - return ['command.queue.async']; - } } diff --git a/src/Connectors/AsyncConnector.php b/src/Connectors/AsyncConnector.php index e725797..9963ed5 100644 --- a/src/Connectors/AsyncConnector.php +++ b/src/Connectors/AsyncConnector.php @@ -3,29 +3,15 @@ namespace Barryvdh\Queue\Connectors; use Barryvdh\Queue\AsyncQueue; -use Illuminate\Queue\Connectors\DatabaseConnector; -use Illuminate\Support\Arr; +use Illuminate\Queue\Connectors\SyncConnector; -class AsyncConnector extends DatabaseConnector +class AsyncConnector extends SyncConnector { - /** - * Establish a queue connection. - * - * @param array $config - * - * @return \Illuminate\Contracts\Queue\Queue + * {@inheritdoc} */ public function connect(array $config) { - return new AsyncQueue( - $this->connections->connection(Arr::get($config, 'connection')), - $config['table'], - $config['queue'], - Arr::get($config, 'expire', 60), - Arr::get($config, 'binary', 'php'), - Arr::get($config, 'binary_args', ''), - Arr::get($config, 'connection_name', '') - ); + return new AsyncQueue($config['after_commit'] ?? null); } } diff --git a/src/Console/AsyncCommand.php b/src/Console/AsyncCommand.php deleted file mode 100644 index 1950e98..0000000 --- a/src/Console/AsyncCommand.php +++ /dev/null @@ -1,99 +0,0 @@ -worker = $worker; - } - - /** - * Execute the console command. - * - * @param WorkerOptions $options - * @return void - */ - public function handle(WorkerOptions $options) - { - $id = $this->argument('id'); - $connection = $this->argument('connection'); - - $this->processJob( - $connection, $id, $options - ); - } - - /** - * Process the job - * - * @param string $connectionName - * @param integer $id - * @param WorkerOptions $options - * - * @throws \Throwable - */ - protected function processJob($connectionName, $id, $options) - { - $manager = $this->worker->getManager(); - - /** @var AsyncQueue $connection */ - $connection = $manager->connection($connectionName); - - $job = $connection->getJobFromId($id); - - if ( ! is_null($job)) { - $this->worker->process( - $manager->getName($connectionName), $job, $options - ); - } - } - - /** - * Get the console command arguments. - * - * @return array - */ - protected function getArguments() - { - return [ - ['id', InputArgument::REQUIRED, 'The Job ID'], - ['connection', InputArgument::OPTIONAL, 'The name of connection'], - ]; - } -} From fd1220fecd73e2dabf9b8090ed05fc1e0d8cadfc Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Mon, 3 Nov 2025 12:44:58 +0100 Subject: [PATCH 35/39] Fix php version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 2c07a27..1905395 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ } ], "require": { - "php": ">=7", + "php": "^8.2", "illuminate/support": "^11.0|^12.0", "illuminate/queue": "^11.0|^12.0" }, From ae194f3b24d5109a3575c24c495da974f5e11711 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Mon, 3 Nov 2025 12:51:11 +0100 Subject: [PATCH 36/39] Update AsyncServiceProvider.php --- src/AsyncServiceProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AsyncServiceProvider.php b/src/AsyncServiceProvider.php index 5fb86a8..9613964 100644 --- a/src/AsyncServiceProvider.php +++ b/src/AsyncServiceProvider.php @@ -7,7 +7,7 @@ use Illuminate\Contracts\Support\DeferrableProvider; use Illuminate\Support\ServiceProvider; -class AsyncServiceProvider extends ServiceProvider implements DeferrableProvider +class AsyncServiceProvider extends ServiceProvider { /** * Add the connector to the queue drivers. From 5ba956db766030b3dd99c79b9baa0120a518c1b0 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Mon, 3 Nov 2025 13:14:55 +0100 Subject: [PATCH 37/39] Use afterResolving --- src/AsyncServiceProvider.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/AsyncServiceProvider.php b/src/AsyncServiceProvider.php index 9613964..2989964 100644 --- a/src/AsyncServiceProvider.php +++ b/src/AsyncServiceProvider.php @@ -3,8 +3,7 @@ namespace Barryvdh\Queue; use Barryvdh\Queue\Connectors\AsyncConnector; -use Barryvdh\Queue\Console\AsyncCommand; -use Illuminate\Contracts\Support\DeferrableProvider; +use Illuminate\Queue\QueueManager; use Illuminate\Support\ServiceProvider; class AsyncServiceProvider extends ServiceProvider @@ -14,22 +13,22 @@ class AsyncServiceProvider extends ServiceProvider * * @return void */ - public function boot() + public function register() { - $this->registerAsyncConnector($this->app['queue']); + $this->registerAsyncConnector(); } /** * Register the Async queue connector. * - * @param \Illuminate\Queue\QueueManager $manager - * * @return void */ - protected function registerAsyncConnector($manager) + protected function registerAsyncConnector() { - $manager->addConnector('async', function () { - return new AsyncConnector; + $this->callAfterResolving(QueueManager::class, function ($manager) { + $manager->addConnector('async', function () { + return new AsyncConnector; + }); }); } } From 193875db72f70d08da29c55eb1d852f9a487a0b4 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Mon, 3 Nov 2025 13:55:23 +0100 Subject: [PATCH 38/39] Revise readme for installation and usage clarity Updated installation instructions and clarified usage notes. --- readme.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/readme.md b/readme.md index e059221..19ada50 100644 --- a/readme.md +++ b/readme.md @@ -7,6 +7,8 @@ The only difference is that the closure is sent to the background without waitin This package is more usable as an alternative for running incidental tasks in the background, without setting up a 'real' queue driver. It is similar to the 'deferred' connection, but it runs in a background process, so might be more suitable for long running tasks. +> Note: Since v0.8 this uses the Concurrently::defer() method instead of the database queue. No database migrations tables are required now. The config can be simplified as below. +> ### Install Require the latest version of this package with Composer From 3fb29a19764ac2376c82b8356081d50437cf3637 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Wed, 5 Nov 2025 09:48:40 +0100 Subject: [PATCH 39/39] Update readme.md --- readme.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/readme.md b/readme.md index 19ada50..e2423e7 100644 --- a/readme.md +++ b/readme.md @@ -1,5 +1,8 @@ # Laravel Async Queue Driver +## Available as `background` in Laravel [v12.37](https://github.com/laravel/framework/releases/tag/v12.37.0) +Update you config to use driver 'background' and you don't need this package anymore. + ## Push a function/closure to the background. Just like the 'sync' or 'deferred' connection, this is not a real queue. It is always fired immediately.