Skip to content
This repository has been archived by the owner. It is now read-only.

Commit

Permalink
Added 2.3.X ActiveRecord compatible backend (without Arel-style scope)
Browse files Browse the repository at this point in the history
  • Loading branch information
etrepat committed Apr 27, 2011
1 parent 3f04a3e commit 68a43d3
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/hirefire.rb
Expand Up @@ -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

##
Expand Down
6 changes: 5 additions & 1 deletion lib/hirefire/backend.rb
Expand Up @@ -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)
Expand Down
33 changes: 33 additions & 0 deletions 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

0 comments on commit 68a43d3

Please sign in to comment.