GoodJob

GoodJob is a multithreaded, Postgres-based ActiveJob backend for Ruby on Rails.

Inspired by Delayed::Job and Que, GoodJob’s design principles are:

  • Stand on the shoulders of ActiveJob. For example, exception and retry behavior.
  • Stand on the shoulders of Ruby on Rails. For example, ActiveRecord ORM, connection pools, and multithreaded support with Concurrent-Ruby.
  • Stand on the shoulders of Postgres. For example, Advisory Locks.
  • Convention over simplicity over performance.

Installation

Add this line to your application's Gemfile:

gem 'good_job', github: 'bensheldon/good_job'

And then execute:

$ bundle

Usage

  1. Create a database migration:

    $ bin/rails g migration CreateGoodJobs
    

    Add to the newly created migration file:

    class CreateGoodJobs < ActiveRecord::Migration[6.0]
      def change
        enable_extension 'pgcrypto'
    
        create_table :good_jobs, id: :uuid do |t|
          t.timestamps
    
          t.text :queue_name
          t.integer :priority
          t.jsonb :serialized_params
          t.timestamp :scheduled_at
        end
      end
    end
    

    Run the migration:

    $ bin/rails db:migrate
    
  2. Configure the ActiveJob adapter:

    # config/environments/production.rb
    config.active_job.queue_adapter = GoodJob::Adapter.new
    
    # config/environments/development.rb
    config.active_job.queue_adapter = GoodJob::Adapter.new(inline: true)
    
  3. In production, the scheduler is designed to run in its own process:

    $ bundle exec good_job
    

Development

To run tests:

# Clone the repository locally
$ git clone [email protected]:bensheldon/good_job.git

# Set up the local environment
$ bin/setup_test

# Run the tests
$ bin/rspec

For developing locally within another Ruby on Rails project:

# Within Ruby on Rails directory...
$ bundle config local.good_job /path/to/local/git/repository

# Confirm that the local copy is used
$ bundle install

# => Using good_job 0.1.0 from https://github.com/bensheldon/good_job.git (at /Users/You/Projects/[email protected])

Releasing

Package maintainers can release this gem with the following gem-release command:

# Sign into rubygems
$ gem signin

# Increase the version number
$ gem bump -v minor --no-commit

# Update the changelog
$ bundle exec rake changelog

# Commit the version and changelog to git
$ bundle commit_version

# Push to rubygems.org
$ gem release

Contributing

Contribution directions go here.

License

The gem is available as open source under the terms of the MIT License.