DLight\Application\Drive\Queue\DbQueue

Mô tả: queue driver lưu job trong DB table dlight_queue_jobs. Hỗ trợ install table (MySQL/SQLite), push job với payload JSON, pop/reserve theo transaction, process 1 job, tracking progress (0..100) và status.

Public API

  • __construct(?DLight\Application\DB $db = null)
  • install(): void
  • push(string $job, array $data = [], ?int $availableAt = null): void
  • pop(string $job): array
  • process(string $job, callable|string|null $handler = null): ?array
  • getQueue(string $job): array
  • getQueueSize(string $job): int
  • getQueueStatus(string $job): string
  • getQueueProgress(string $job): float
  • setProgress(int $id, float $progress): void

Job handler format

  • Class: App\Jobs\ExampleJob::class → nếu object callable thì gọi $instance($data, $context, $queue), nếu có handle() thì gọi handle().
  • Class@method: App\Jobs\ExampleJob@handle → gọi method tương ứng.

Demo

use DLight\Application\Drive\Queue\DbQueue;

$q = new DbQueue();
$q->install();

$q->push(App\\Jobs\\ExampleJob::class, ['id' => 1]);

// Process 1 item
$item = $q->process(App\\Jobs\\ExampleJob::class);

// Inspect queue
$all = $q->getQueue(App\\Jobs\\ExampleJob::class);
$progress = $q->getQueueProgress(App\\Jobs\\ExampleJob::class);