All Projects → salsify → delayed_job_worker_pool

salsify / delayed_job_worker_pool

Licence: MIT license
Worker process pooling for Delayed Job

Programming Languages

ruby
36898 projects - #4 most used programming language
HTML
75241 projects
CSS
56736 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to delayed job worker pool

i18n lazy scope
Use lazy lookup with custom i18n scopes.
Stars: ✭ 11 (-65.62%)
Mutual labels:  gem
index shotgun
duplicate index checker 🔥 🔫 👮
Stars: ✭ 35 (+9.38%)
Mutual labels:  gem
sinator
Sinatra application generator
Stars: ✭ 19 (-40.62%)
Mutual labels:  gem
churnalizer
Analyze your Ruby app for Churn vs Complexity
Stars: ✭ 17 (-46.87%)
Mutual labels:  gem
rails-heroicon
Ruby on Rails views helpers for the awesome heroicons by Steve Schoger.
Stars: ✭ 23 (-28.12%)
Mutual labels:  gem
rsgem
Rootstrap way ® to generate gems
Stars: ✭ 26 (-18.75%)
Mutual labels:  gem
active record-updated at
Touch `updated_at` by default with calls to `update_all` and `update_column(s)`
Stars: ✭ 27 (-15.62%)
Mutual labels:  gem
perf check
PERRRFFF CHERRRRK!
Stars: ✭ 16 (-50%)
Mutual labels:  gem
carender
📅 A monthly calendar for Rails application
Stars: ✭ 15 (-53.12%)
Mutual labels:  gem
multi-tenancy-devise
mtdevise adds basecamp style user logins to your ruby on rails application.
Stars: ✭ 27 (-15.62%)
Mutual labels:  gem
backlog kit
Client library for the Nulab's Backlog API version 2 written in Ruby.
Stars: ✭ 28 (-12.5%)
Mutual labels:  gem
mixin bot
A simple API wrapper for Mixin Network in Ruby
Stars: ✭ 12 (-62.5%)
Mutual labels:  gem
als typograf
Ruby client for ArtLebedevStudio.RemoteTypograf Web Service.
Stars: ✭ 15 (-53.12%)
Mutual labels:  gem
my api client
A framework of Web API Client. Provides features error handling, retrying, pagination and so on.
Stars: ✭ 19 (-40.62%)
Mutual labels:  gem
carrierwave-cloudflare
🎑 This Rails gem integrates Carrierwave with Cloudflare Image Resizing
Stars: ✭ 24 (-25%)
Mutual labels:  gem
exception hunter
Crash reporting engine to hunt down bugs 🐞
Stars: ✭ 78 (+143.75%)
Mutual labels:  gem
drape
Drape – Reincarnation of Draper for Rails 5
Stars: ✭ 57 (+78.13%)
Mutual labels:  gem
google docs-ruby
A library which allows you to edit your spreadsheets with pleasure
Stars: ✭ 18 (-43.75%)
Mutual labels:  gem
colorama
A Gem for extracting the most prevalent colors from an image
Stars: ✭ 20 (-37.5%)
Mutual labels:  gem
bundle outdated formatter
Formatter for `bundle outdated` command
Stars: ✭ 16 (-50%)
Mutual labels:  gem

Delayed Job Worker Pool

Gem Version Build Status Code Climate

Delayed Job's built-in worker pooling daemonizes all worker processes. This is great for certain environments but not so great for environments like Heroku that really want your processes to run in the foreground. Delayed Job Worker Pool runs a pool of Delayed Job workers without daemonizing them.

Salsify is currently using Delayed Job Worker Pool to run multiple Delayed Job workers on a single Heroku PX dyno. Read more about our experience using this gem on our blog.

This gem only works with MRI on Linux/MacOS X.

Installation

Add this line to your application's Gemfile:

gem 'delayed_job_worker_pool'

And then execute:

$ bundle

Or install it yourself as:

$ gem install delayed_job_worker_pool

Usage

From your Rails root directory run:

delayed_job_worker_pool <config file>

The config file is a Ruby DSL inspired by the Puma configuration DSL. Here's an example:

worker_group do |g|
  g.workers = Integer(ENV['NUM_WORKERS'] || 1)
  g.queues = (ENV['QUEUES'] || ENV['QUEUE'] || '').split(',')
  g.sleep_delay = ENV['WORKER_SLEEP_DELAY']
end

preload_app

# This runs in the master process after it preloads the app
after_preload_app do
  puts "Master #{Process.pid} preloaded app"
  
  # Don't hang on to database connections from the master after we've 
  # completed initialization
  ActiveRecord::Base.connection_pool.disconnect!
end

# This runs in the worker processes after it has been forked
on_worker_boot do |worker_info|
  puts "Worker #{Process.pid} started"
  
  # Reconnect to the database
  ActiveRecord::Base.establish_connection
end

# This runs in the master process after a worker starts
after_worker_boot do |worker_info|
  puts "Master #{Process.pid} booted worker #{worker_info.name} with " \
        "process id #{worker_info.process_id}"
end

# This runs in the master process after a worker shuts down
after_worker_shutdown do |worker_info|
  puts "Master #{Process.pid} detected dead worker #{worker_info.name} " \
        "with process id #{worker_info.process_id}"
end

You can configure multiple worker groups, i.e.:

worker_group(:default) do |g|
  g.workers = 1
  g.queues = ['default']
end

worker_group(:mails) do |g|
  g.workers = 1
  g.queues = ['mail]
end

Here's more information on each setting:

  • worker_group - You need at least one worker group. Group settings can be set as illustrated above. Worker group settings:
    • workers - The number of Delayed Job worker processes to fork. The master process will relaunch workers that fail.
    • Delayed Job worker settings (queues, min_priority, max_priority, sleep_delay, read_ahead) - These are passed through to the Delayed Job worker.
  • preload_app - This forces the master process to load Rails before forking worker processes causing the memory consumed by the code to be shared between workers. If you use this setting make sure you re-establish any necessary connections in the on_worker_boot callback.
  • after_preload_app - A callback that runs in the master process after preloading the app but before forking any workers.
  • on_worker_boot - A callback that runs in the worker process after it has been forked.
  • after_worker_boot - A callback that runs in the master process after a worker has been forked.
  • after_worker_shutdown - A callback that runs in the master process after a worker has been shutdown.

All settings are optional and nil values are ignored.

Upgrading from v0.2.x

  • Convert your worker settings to a single worker group (see Usage)
  • Please note the delayed job worker names changed to include group: <group_name>, e.g. if you are monitoring them by their name

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/salsify/delayed_job_worker_pool.

License

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].