openflighthpc / flight-control

0 stars 0 forks source link

Use background jobs and resque #70

Closed timalces closed 1 year ago

timalces commented 1 year ago

Aims to resolve #57. Dependent upon #69

Background Jobs Updates various rake tasks to no longer rely on fork to paralellise actions for multiple projects, instead converting them to background jobs.

This allows for a much more controlled completion of the tasks, especially on dokku where there otherwise may be a risk of control taking too much/ an unpredictable amount of host resources.

This is also important as most of these tasks are run multiple times a day and for every active project. It will also make scaling running these tasks (independent of the web app) more straightforward in the future.

These background tasks are sent to one of three queues, based on their priority: high, medium or low.

Redis and Resque Adds implementation of Resque (which uses redis) for handling these background jobs.

Note: if using resque (e.g. on staging) and you want to run a rake task with text output, you will need to override the queue adapter, as resque will print the text within its own process (and so not be visible in your console). E.g. QUEUE_ADAPTER=inline rake daily_reports:generate:all[true,true,true]

Resque Admin Interface Admins can view and take some actions on background jobs via the resque admin page, accessible at /resque. Note: this path will break if you have no redis service running

Screenshot from 2022-11-24 16-16-37

Dokku Config Adds config for using redis on dokku, with instructions for dokku to create a dedicated container to handle these background jobs

Testing note: if you are using redis on your local machine and you are also using Flight Center, you need to run separate redis services for each

timalces commented 1 year ago

Merging this as appears to be working. We should continue to monitor the workers, jobs and resource utilisation, especially when there are more projects, and therefore more background tasks being run.