diff --git a/composer.json b/composer.json
index 0284f5c..70c2deb 100644
--- a/composer.json
+++ b/composer.json
@@ -25,6 +25,7 @@
"blitz-php/coding-standard": "^1.4",
"blitz-php/framework": "^0.12",
"blitz-php/http-client": "^0.0.2",
+ "blitz-php/queue": "^0.2.0",
"kahlan/kahlan": "^6.0",
"phpstan/phpstan": "^2.1"
},
diff --git a/src/Scheduler.php b/src/Scheduler.php
index 6b5ca4d..fe1928d 100644
--- a/src/Scheduler.php
+++ b/src/Scheduler.php
@@ -13,6 +13,9 @@
namespace BlitzPHP\Tasks;
+use BlitzPHP\Contracts\Queue\ShouldQueue;
+use BlitzPHP\Queue\Job;
+
/**
* @credit CodeIgniter4 - CodeIgniter\Tasks\Scheduler
*/
@@ -85,6 +88,25 @@ public function url(string $url): Task
return $this->createTask('url', $url);
}
+ /**
+ * Planifie l'execution d'un job dans la file d'attente.
+ *
+ * @param class-string|Job $job
+ */
+ public function job(object|string $job, ?string $queue = null, ?string $driver = null)
+ {
+ return $this->call(function () use ($job, $queue, $driver) {
+ /** @var Job $job */
+ $job = is_string($job) ? service('container')->make($job) : $job;
+
+ if ($job instanceof ShouldQueue) {
+ service('queue')->driver($driver ?? $job->driver ?? null)->pushOn($queue ?? $job->queue(), $job);
+ } else {
+ $job->execute();
+ }
+ })->named(is_string($job) ? $job : $job::class);
+ }
+
/**
* @param mixed $action
* @param list $parameters Parameters eventuels a transmettre aux taches.