Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .php-cs-fixer.dist.php
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
<?php

/**
* This file is part of BlitzPHP Tasks.
* This file is part of BlitzPHP Queue.
*
* (c) 2025 Dimitri Sitchet Tomkeu <devcode.dst@gmail.com>
* (c) 2026 Dimitri Sitchet Tomkeu <devcode.dst@gmail.com>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
Expand DownExpand Up@@ -42,5 +42,5 @@
'BlitzPHP Queue',
'Dimitri Sitchet Tomkeu',
'devcode.dst@gmail.com',
2026
2026,
);
4 changes: 2 additions & 2 deletions README.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -50,7 +50,7 @@ Créez votre premier Job via la commande:
php klinge queue:job Example
```

Et ajoutez-le au tableau des gestionnaires (`handlers`) dans le fichier `app\Config\queue.php`:
Et ajoutez-le au tableau des gestionnaires (`jobs`) dans le fichier `app\Config\queue.php`:

```php
// ...
Expand All@@ -62,7 +62,7 @@ use App\Jobs\Example;
return [
// ---

'handlers' => [
'jobs' => [
'my-example' => Example::class
],

Expand Down
15 changes: 8 additions & 7 deletions composer.json
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
{
"name": "blitz-php/queue",
"description": "Gestionnaire de file d'attente pour BlitzPHP",
"keywords": ["blitz-php", "blitz php", "queue", "database", "redis", "predis" ],
"homepage": "https://github.com/blitz-php/tasks",
"keywords": ["blitz-php", "blitz php", "queue", "worker", "database", "redis", "predis", "file d'attente" ],
"homepage": "https://github.com/blitz-php/queue",
"license": "MIT",
"type": "library",
"authors": [
Expand All@@ -13,11 +13,12 @@
}
],
"require": {
"php": "^8.1"
"php": "^8.1",
"blitz-php/database": "^0.8.3"
},
"require-dev": {
"blitz-php/coding-standard": "^1.4",
"blitz-php/framework": "^0.11.3",
"blitz-php/framework": "^0.12.4",
"kahlan/kahlan": "^6.0",
"phpstan/phpstan": "^2.1",
"predis/predis": "^2.0 || ^3.0",
Expand All@@ -37,9 +38,9 @@
}
},
"suggest": {
"ext-redis": "If you want to use RedisHandler",
"predis/predis": "If you want to use PredisHandler",
"php-amqplib/php-amqplib": "If you want to use RabbitMQHandler"
"ext-redis": "Si vous souhaitez utiliser RedisDriver",
"predis/predis": "Si vous souhaitez utiliser PredisDriver",
"php-amqplib/php-amqplib": "Si vous souhaitez utiliser RabbitMQDriver"
},
"scripts": {
"test": "vendor/bin/kahlan",
Expand Down
5 changes: 2 additions & 3 deletions spec/bootstrap.php
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
<?php

/**
* This file is part of BlitzPHP Tasks.
* This file is part of BlitzPHP Queue.
*
* (c) 2025 Dimitri Sitchet Tomkeu <devcode.dst@gmail.com>
* (c) 2026 Dimitri Sitchet Tomkeu <devcode.dst@gmail.com>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/

125 changes: 125 additions & 0 deletions src/CallQueuedClosure.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
<?php

/**
* This file is part of BlitzPHP Queue.
*
* (c) 2026 Dimitri Sitchet Tomkeu <devcode.dst@gmail.com>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/

namespace BlitzPHP\Queue;

use BlitzPHP\Contracts\Container\ContainerInterface;
use BlitzPHP\Queue\Traits\Dispatchable;
use BlitzPHP\Queue\Traits\InteractsWithQueue;
use BlitzPHP\Queue\Traits\SerializesModels;
use Closure;
use Laravel\SerializableClosure\SerializableClosure;
use ReflectionFunction;
use Throwable;

/**
* Job enveloppe d'une Closure sérialisable, exécutable par le worker.
*/
class CallQueuedClosure
{
use Dispatchable;
use InteractsWithQueue;
use SerializesModels;

/**
* Instance de Closure sérialisable.
*
* @var SerializableClosure
*/
public $closure;

/**
* Nom assigné au job.
*/
public ?string $name = null;

/**
* Callbacks à exécuter en cas d'échec.
*/
public array $failureCallbacks = [];

/**
* Indique si le job doit être supprimé lorsque des modèles sont introuvables.
*/
public bool $deleteWhenMissingModels = true;

/**
* Crée une nouvelle instance de job.
*/
public function __construct(SerializableClosure $closure)
{
$this->closure = $closure;
}

/**
* Crée une nouvelle instance de job.
*/
public static function create(Closure $job): self
{
return new self(new SerializableClosure($job));
}

/**
* Exécute le job.
*/
public function handle(ContainerInterface $container): void
{
$container->call($this->closure->getClosure(), ['job' => $this]);
}

/**
* Ajoute un callback exécuté si le job échoue.
*/
public function onFailure(callable $callback): self
{
$this->failureCallbacks[] = $callback instanceof Closure
? new SerializableClosure($callback)
: $callback;

return $this;
}

/**
* Traite l'échec du job.
*/
public function failed(Throwable $e): void
{
foreach ($this->failureCallbacks as $callback) {
$callback($e);
}
}

/**
* Retourne le nom d'affichage du job enfilé.
*/
public function displayName(): string
{
$closure = $this->closure instanceof SerializableClosure
? $this->closure->getClosure()
: $this->closure;

$reflection = new ReflectionFunction($closure);

$prefix = null === $this->name ? '' : "{$this->name} - ";

return $prefix . 'Closure (' . basename($reflection->getFileName()) . ':' . $reflection->getStartLine() . ')';
}

/**
* Assigne un nom au job.
*/
public function name(string $name): self
{
$this->name = $name;

return $this;
}
}
Loading