Q: Can someone explain how to create a module that uses worker queues that can run a command line tool on a conversion server?
There's really nothing special about a module that uses queues - basically you:
- register the name of the function that will be run when a queue entry is received that matches the queue - for example:
jrCore_register_queue_worker('jrAudio', 'audio_conversions', 'jrAudio_convert_file', 0, 1);
This tells the core:
- when a new queue entry comes in to the "audio_conversions" queue
- call the "jrAudio_convert_file" function and pass it $_queue - $_queue contains all the data that was passed in when the queue was created
- "0" means there is NO LIMIT to the number of queue entries this function will process in a row (i.e. if you set it to "1" it would process 1 queue entry then exit).
- the "1" says "only allow one function of this type to be running at the same time".
From the worker function:
- if you return TRUE the queue entry is deleted (that's how you tell the core you were succesful and the queue entry can now be removed).
- if you return FALSE then the queue goes back into the stack for another worker to pickup
- if you return a NUMBER it tells the core to "sleep" the queue for that many seconds - i.e. if you did:
it would put the queue entry back on the stack but not allow any worker to pick it up for 3600 seconds.
So basically you just need to register the queue worker in the module's init function and that's it.