diff --git a/lib/hirefire.rb b/lib/hirefire.rb index 0ad12f0..dabf934 100644 --- a/lib/hirefire.rb +++ b/lib/hirefire.rb @@ -44,8 +44,9 @@ module Backend ## # HireFire::Backend::DelayedJob namespace module DelayedJob - autoload :ActiveRecord, File.join(DELAYED_JOB_PATH, 'active_record') - autoload :Mongoid, File.join(DELAYED_JOB_PATH, 'mongoid') + autoload :ActiveRecord, File.join(DELAYED_JOB_PATH, 'active_record') + autoload :OldActiveRecord, File.join(DELAYED_JOB_PATH, 'old_active_record') + autoload :Mongoid, File.join(DELAYED_JOB_PATH, 'mongoid') end ## diff --git a/lib/hirefire/backend.rb b/lib/hirefire/backend.rb index 042d2c6..1898b20 100644 --- a/lib/hirefire/backend.rb +++ b/lib/hirefire/backend.rb @@ -18,7 +18,11 @@ def self.included(base) # Delayed Job specific backends if defined?(::Delayed) if defined?(::Delayed::Backend::ActiveRecord::Job) - base.send(:include, HireFire::Backend::DelayedJob::ActiveRecord) + if ActiveRecord::VERSION::STRING >= '3.0.0' + base.send(:include, HireFire::Backend::DelayedJob::ActiveRecord) + else + base.send(:include, HireFire::Backend::DelayedJob::OldActiveRecord) + end end if defined?(::Delayed::Backend::Mongoid::Job) diff --git a/lib/hirefire/backend/delayed_job/old_active_record.rb b/lib/hirefire/backend/delayed_job/old_active_record.rb new file mode 100644 index 0000000..7c5062b --- /dev/null +++ b/lib/hirefire/backend/delayed_job/old_active_record.rb @@ -0,0 +1,33 @@ +# encoding: utf-8 + +module HireFire + module Backend + module DelayedJob + module OldActiveRecord + + ## + # Counts the amount of queued jobs in the database, + # failed jobs are excluded from the sum + # + # @return [Fixnum] the amount of pending jobs + def jobs + ::Delayed::Job.all( + :conditions => ['failed_at IS NULL and run_at <= ?', Time.now.utc] + ).count + end + + ## + # Counts the amount of jobs that are locked by a worker + # + # @return [Fixnum] the amount of (assumably working) workers + def workers + ::Delayed::Job.all( + :conditions => 'locked_by IS NOT NULL' + ).count + end + + end + end + end +end +