Skip to content

saltandvinegarcrisps/queue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Example

ReportJob.php

$queue = new Queue\ArrayQueue;
$queue->setChannel('reports');

$job = new Queue\Job('Report@export', ['csv', '[email protected]']);
$queue->push($job);

$job = new Queue\Job(['Report', 'export'], ['csv', '[email protected]']);
$queue->push($job);

$job = new Queue\Job('Report', ['csv', '[email protected]']); // Report@handle
$queue->push($job);

$job = new Queue\Job(Report::class, ['csv', '[email protected]']); // 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();

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages