Webador / SlmQueue

Laminas / Mezzio module that integrates with various queue management systems.
Other
137 stars 56 forks source link

Frustrated to get queues working #139

Closed mikemix closed 10 years ago

mikemix commented 10 years ago

Quoting docs at https://github.com/juriansluiman/SlmQueue/blob/master/docs/2.Configuration.md, to get the queue manager I need to do:

$queueManager = $sl->get('SlmQueue\Queue\QueuePluginManager');

but this code does not work and returns an error:

Zend\ServiceManager\ServiceManager::get was unable to fetch or create an instance for SlmQueue\Queue\QueuePluginManager

In the docs there are a lot of examples on injecting the queue from the constructor:

public function __construct(QueueInterface $queue)
{
    $this->queue = $queue;
}

But there's no example how to instantiate the queue object. Except for one mentioned at the top, which is not working obviously.

eddiejaoude commented 10 years ago

@mikemix As the ticket has been closed, I am guessing you solved the issue?

Could you put the solution here, so that other people could benefit & we could possibly update the documentation if it is missing a step or not clear.

mikemix commented 10 years ago

This is my mistake and I humbly apologize. Only one question which comes to my mind, when I add the job to the queue, how and when am I supposed to tell Beanstalkd to start working on that job?

I'm working with SlmBeanstalkd, and yes, there is a command line tool to start the job, but what's confusing is should I run this command with some system()/exec() function after the job was added?

When I master some basics, I'm going to create simple ZF2 skeleton application with example queues up and running so every newbie like myself could benefit.

eddiejaoude commented 10 years ago

There is some documentation to run the job worker with something like Supervisor (if you are using Ubuntu)

basz commented 10 years ago

supervisor runs great on osx too! brew install supervisor

mikemix commented 10 years ago

Is this tool required to run beanstalk jobs then?

basz commented 10 years ago

no, you can start the queue manually too...

php public/index.php queue beanstalk <queueName> --start

or use any process manager you like or you could even skip using slm-queue workers altogether and use slim-queue only to push jobs into a queue. Mind you that the payload of the job contains some things specifically for slml-queue workers.

mikemix commented 10 years ago

What to do next when I add the job to the queue?

1) Do I receive some unique ID after the push? 2) How to check that job's status and receive the output?

In my app I need to generate a large PDF document. After the job is done I would like to show a download link to the user.

eddiejaoude commented 10 years ago

1) Do I receive some unique ID after the push?

I did a PR for this a while ago, I will take a look if it made it in.

2) How to check that job's status and receive the output?

It depends what your job is doing with the result.

In my app I need to generate a large PDF document. After the job is done I would like to show a download link to the user.

If you want to push back to the browser when the job is completed, you will need to use websockets

mikemix commented 10 years ago

I'm going after another approach then without dynamic check on job's status. Thank you for your help.

juriansluiman commented 10 years ago

@mikemix when you push a job into a queue, often an id is assigned (which is also the case for beanstalkd). You can use that identifier and use it to query for its stats. At this moment there is no stat() for the SlmQueue queue implementation, but it is supported by Pheanstalk (so hint, it might be useful for SlmQueueBeanstalkd too!).

A kind-of implementation:

// $sl instanceof ServiceManager
$queue = $sl->get('SlmQueue\Queue\QueuePluginManager')->get('my_queue');
$pheanstalk = $sl->get('SlmQueueBeanstalkd\Service\PheanstalkService');

$job = new MyExampleJob();
$queue->push($job);

echo $job->getId();

$response = $pheanstalk->statsJob($job);
// $response some unknown data blob with status info

You can send the job id from your controller to your view. Then load the id as javascript variable. On the client's side you can poll the job with given id if the job is finished or not.