RQ Job Queues

Pootle makes use of RQ to manage background jobs.

Currently statistics are calculated using background jobs and we expect more components to use it in future.

The RQ queue is managed by Redis and it is setup in the RQ_QUEUES and CACHES settings.

Running job workers

The queue is processed by Workers. Any number of workers may be started and will process jobs in the default queue. The rqworker command is used to start a Worker.

Monitoring the queue

At the simplest level the Admin dashboard will tell you if the queue is active and how many workers are available to service the queue. It also lists the number of pending jobs and the number of failed jobs. This gives you a quick way to see if anything is wrong.

Working with failed jobs

If a job fails it needs to be investigated. In most cases a traceback will indicate why the job failed.

The simplest way to work with queues and jobs is to use rq-dashboard, though you likely don’t want to deploy that on a production server. With this you can see the jobs in the queue, you can check the tracebacks and you can retry failed jobs.

In the case of a production server you can make use of the following commands to manage jobs:

$ redis-cli -n 2 lrange rq:queue:default 0 -1

This will display all pending job IDs in the default queue. We’re using the Redis DB number 2, the default RQ queue on a standard Pootle install.

$ redis-cli -n 2 lrange rq:queue:failed 0 -1

This will display the failed job IDs.

To investigate a failed job simply add rq:job: prefix to a job ID and use a command such as this:

$ redis-cli -n 2 hgetall rq:job:60ed13df-0ce5-4b98-96f0-f8e0294ba421

This will allow you to see any traceback and investigate and solve them.

To push failed jobs back into the queue we simply run the retry_failed_jobs management command.

Dirty statistics

When we count stats with refresh_stats Pootle will track a dirty count so that it knows when the counts for that part of the tree is complete.

When debugging a situation where the counts aren’t completing it is helpful to see the dirty counts. To retrieve these use:

$ redis-cli -n 2 zrank "pootle:dirty:treeitems" "/projects/terminology/"

Or to get a complete list for the server, including the scores:

$ redis-cli -n 2 zrange "pootle:dirty:treeitems" 0 -1 withscores

The banner that shows that stats are being calculated is displayed when pootle:refresh:stats is present. Only remove this if you are confident that all else is good and that the stats are fine or to be generated again.

$ redis-cli -n 2 del pootle:refresh:stats