Skip to main content

Good job integration

Good job is an active_job adatper that have several advantages over sidekiq:

  • It use postgres, no need to have a dedicated Redis database in append-only-mode
  • It does not loose job by default, no need for sidekick-plus

decidim-voca prepares the good-job adapter with decidim-friendly values. It will:

  • Reproduce sidekiq default behaviour (restart failing jobs)
  • Mount a system-protected dashboard on /system/active_jobs
  • Add environment variable configuration for 12factors config

Installation

If you installed decidim-voca previously, the migrations for good jobs are already installed. To enable the good_job use, you need to define the active_job adapter to good_job in your config/environments/production.rb:

# config/environments/production.rb
Rails.application.configure do
config.active_job.queue_adapter = :good_job
end

This will enable the use of good_job, and mount the dashboard. To run good_job in an external process, you will need the binstub:

bundle binstubs good_job
# bin/good_job gets created
warning

Pool connection
On async server mode, good_job is configured with 5 additional threads. This means it will uses more db connection (1 per threads). As the default for most configurations are to set the pool size to the value RAILS_MAX_THREADS, your application will broke if you do not setup pool to rails max threads + good job max threads = pool size. See Configuring a database guide

Async Server or External

Good Job offers differents mode, for simplicity purpose, decidim-voca supports two mode:

  • async_server: Good job will run within your rails server, and execute tasks when it can. Great for small instances.
  • external: Good job will run separatly.

The main change is on the infrastructure side:

  • async_server: use threads inside the puma server process
  • external: use the bin/good_job process to manage its threads
Async modeExternal mode
Async modeExternal mode
Async mode: Sending email exampleExternal mode: Sending email example

Environment Variables

We use environment variables to configure the module:

VariableDescriptionDefaultOptions
VOCA_ACTIVE_JOB_EXECUTION_MODEMode for good_job executionasync_serverasync_server, external
VOCA_GOOD_JOB_RETRYNumber of retries before discarding a job5Integer
VOCA_GOOD_JOB_MAX_THREADSMaximum number of threads for job processing5Integer
VOCA_GOOD_JOB_POLL_INTERVALPolling interval in seconds30Integer
VOCA_GOOD_JOB_SHUTDOWN_TIMEOUTShutdown timeout in seconds120Integer
VOCA_GOOD_JOB_QUEUESQueue names to process*String (see documentation)

References