Skip to content

Instantly share code, notes, and snippets.

@JeffLuckett
Created November 8, 2017 19:26
Show Gist options
  • Save JeffLuckett/86407fdc5bf36c6d5ca19d304b851310 to your computer and use it in GitHub Desktop.
Save JeffLuckett/86407fdc5bf36c6d5ca19d304b851310 to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
namespace :jobs do
path = File.expand_path('../../../config/async_job_queues.yml.erb', __FILE__)
DJ_SETTINGS = YAML.safe_load(
ERB.new(File.new(path).read).result
).with_indifferent_access[:back_ends][:delayed_job]
def all_queues
DJ_SETTINGS[:queue_pools].reduce([]) do |queue_list, pool|
queue_list << pool[:dj_opts][:queues]
end.flatten.uniq
end
def config_for_queue(queue)
DJ_SETTINGS[:queues][queue]
end
namespace :start do
all_queues.each do |job|
desc "Start a #{job} queue worker"
task job => :environment do
Delayed::Worker.new(queues: [job], quiet: false).start
end
end
desc 'Start all configured queues forked from a Master foreground process.'
task all: :environment do
path = File.expand_path('../../../config/dj_worker_pools.rb', __FILE__)
options = DelayedJobWorkerPool::DSL.load(path)
DelayedJobWorkerPool::WorkerPool.new(options).run
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment