Processing Asynchronous Jobs - QutEcoacoustics/baw-server GitHub Wiki
Asynchronous Jobs
Resque
Asynchronous jobs are implemented using Resque. This gem wraps a redis-based data store and rake-based worker system. Items of work (Jobs) are queued onto named queues stored in redis, with the name of the class that performs the processing and the arguments for the class's perform method.
Queues
A queue is a collection of jobs. Each queue contains unique jobs of the same type. Queue names are specified by Action classes in baw-workers.
To add items to a queue, use the enqueue method provided by the relevant action class. This will ensure that the parameters are validated and the correct queue name is used.
Each environment has a different queue suffix, and each type of job has a dedicated queue prefix. For example, the MediaAction class can process audio file cutting and spectrogram generation. The jobs it creates can only be queued on to a media queue: media_production, media_staging, media_development.
Action classes and Workers
Action classes define the processing a worker will perform. A worker is a rake task that runs indefinitely. Action classes define:
- the
queuethey will enqueue to and dequeue from - a
performmethod which processes a single job - an
enqueuemethod that provides an easy way to queue a new job