Webador / SlmQueueBeanstalkd

Beanstalkd adapter for SlmQueue module
Other
10 stars 26 forks source link

Question on Executing Jobs #45

Closed EMCP closed 10 years ago

EMCP commented 10 years ago

I was so confused at first, filling Beanstalkd with jobs and not seeing them get executed. Now I understand that they piled up until I hit php index.php queue beanstalkd default ..All my output generated after that on the console.

My question is.. is this normal? I thought once beanstalkd was running it would execute jobs. What are the best practices for managing the php index.php queue beanstalkd default calls?

Is this something configurable through slmqueueBeanstalkd ? I guess each time I execute that.. it represents a worker?

juriansluiman commented 10 years ago

@EMCP the workers are ran by an SlmQueue\Worker\WorkerInterface. The how's & where's of workers is documented in the SlmQueue documentation in the chapter about workers.

You probably don't want to run the CLI commands manually every time, so there are tools available to manage workers. One of the easiest tools to use is supervisord and a small amount of documentation is written about it in the chapter of worker management.

My question is.. is this normal? I thought once beanstalkd was running it would execute jobs. What are the best practices for managing the php index.php queue beanstalkd default calls?

Yes, this is normal. Beanstalkd is simply a "database". It stores the jobs, but it doesn't do anything about execution.

Is this something configurable through slmqueueBeanstalkd ? I guess each time I execute that.. it represents a worker?

Every time you invoke php index.php queue, a new worker is started. If you open 5 terminal windows and in every window you run php index.php queue beanstalkd default, then there are 5 workers listening on the default beanstalkd tube. If you push a job onto the queue, one of the workers will pick it up. If you cancel a worker, then 4 are left running.

Notice it is recommended to add a --timeout call (e.g. --timeout=1). The worker will continue the listen loop every 1 second when there is no job found. That helps in managing the workers when no jobs are available: if you want to kill a worker while the queue is empty, an infinite timeout will prevent you from stopping the worker.

EMCP commented 10 years ago

Excellent, I'll look into those doc sections. Thank you! I had previously tried to use PHP-Resque with ZF2 and the namespaces was preventing workers from seeing my classes.