Closed mikemix closed 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.
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.
There is some documentation to run the job worker with something like Supervisor (if you are using Ubuntu)
supervisor runs great on osx too! brew install supervisor
Is this tool required to run beanstalk jobs then?
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.
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.
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
I'm going after another approach then without dynamic check on job's status. Thank you for your help.
@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.
Quoting docs at https://github.com/juriansluiman/SlmQueue/blob/master/docs/2.Configuration.md, to get the queue manager I need to do:
but this code does not work and returns an error:
In the docs there are a lot of examples on injecting the queue from the constructor:
But there's no example how to instantiate the queue object. Except for one mentioned at the top, which is not working obviously.