No commit activity in last 3 years
No release in over 3 years
Adds job groups to delayed_job_mongoid
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

~> 1.1.5
~> 2.1.1
~> 2.0.0.rc.4
~> 3.0
 Project Readme

delayed job groups

Adds grouping to jobs. Only 1 job in each group will be executed regardless of the number of workers.

Requires

  • rails 3
  • Latest version of delayed_job from github - current release(v2.1.0.pre2) does not support enqueue hooks
  • active_record backend - other backends aren't supported

Install

# Gemfile
gem 'delayed_job_groups'

Add migration to add lock_group column

# db/migrate/xxx_add_lock_group_to_delayed_jobs
class AddLockGroupToDelayedJobs < ActiveRecord::Migration
  def self.up
    add_column :delayed_jobs, :lock_group, :string
  end

  def self.down
    remove_column :delayed_jobs, :lock_group
  end
end

Usage

Job groups are strings. You need to specify what the job_group should be in a block. Delayed job will only perform 1 job from each group at a time.

Job groups for standard jobs

 class ResizeImageJob < Struct.new(:format)
	 job_group{ |resize_image_job| resize_image_job.format }
	
	 def perform
		 resize_to format
	 end
 end

Job groups when using delay()

 class Person < ActiveRecord::Base
	 job_group{ |person| person.role }
	
	 def send_welcome
	    ...
	 end
 end

 Person.create(:role => "admin").delay.send_welcome

Job groups when methods are declared asynchonous

 class Person < ActiveRecord::Base
	 job_group{ |person| person.role }

	 def send_welcome
	    ...
	 end
	 handle_asynchronously :send_welcome
 end

 Person.create(:role => "admin").send_welcome