Use of queueing

The queue service provides the following functions:

  • Add
  • Get
  • Process
  • Delete

Getting a queue

First off, we need to determine which queue (or channel) we want to interact with. Our examples will use my.queue when adding, retrieving and deleting jobs from the queue.

$queue = Jadu_Service_Container::getInstance()->getQueue('my.queue');

Adding a job

The add method requires an array to be passed. This will become JSON encoded on the way in.

    'foo' => 'bar',
    'bar' => 'baz',
    'baz' => 'foo

Getting a job

Getting a job will give you mixed results. This allows you to pass the job object around in order to get the data and also acknowledge completion.

$job = $queue->get();

Getting data from a job

Use the getMessage helper message to transform the $job object into user data.

$message = $queue->getMessage($job);

Removing a job

Finally we want to remove the job from the queue once we're "done".


Processing jobs

All of this can be handled within the process method, which takes a callable. This allows your to state a callable method that will invoke each time a message is fetched.

    // do something with $data
    // ...

    // For 0.1.6 return true in order to acknowledge completion
    return true;

results matching ""

    No results matching ""