rwarasaurus / queue
Queue
0.1.7
2019-02-04 09:37 UTC
Requires
- php: >=7
Requires (Dev)
- friendsofphp/php-cs-fixer: dev-master
- phpspec/phpspec: ^3.2
- phpstan/phpstan: ~0
- slam/phpstan-extensions: ~2
- symfony/var-dumper: ~4
This package is not auto-updated.
Last update: 2024-11-10 14:46:31 UTC
README
Example
ReportJob.php
$queue = new Queue\ArrayQueue;
$queue->setChannel('reports');
$job = new Queue\Job('Report@export', ['csv', 'bob@acme.com']);
$queue->push($job);
$job = new Queue\Job(['Report', 'export'], ['csv', 'bob@acme.com']);
$queue->push($job);
$job = new Queue\Job('Report', ['csv', 'bob@acme.com']); // Report@handle
$queue->push($job);
$job = new Queue\Job(Report::class, ['csv', 'bob@acme.com']); // Report@handle
$queue->push($job);
ReportsWorker.php
$queue = new Queue\ArrayQueue;
$queue->setChannel('reports');
$handler = function(string $message) {
$job = Queue\Job::parse($message);
// maybe check attempts
if($job->getAttempts() > 3) {
$logger->error('Job Failed', ['job' => $job]);
}
$task = $job->getTask(); // Report@export
[$class, $action] = explode('@', $task, 2);
$ref = new ReflectionClass($class);
$result = $ref->getMethod($action)->invokeArgs(new $class, $job->getArgs());
};
$interval = 10; // seconds
$worker = new Queue\Worker($queue, $handler, $interval);
$worker->run();