Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add DM compatibility #37

Merged
merged 1 commit into from

3 participants

@okbreathe

Added compatibility with the DataMapper ORM - tested on a production site. Does require https://github.com/collectiveidea/delayed_job_data_mapper however

@meskyanichi
Owner

Thanks!

@meskyanichi meskyanichi merged commit 0fab407 into hirefire:develop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 10, 2011
  1. @exitface

    Add DM compatibility

    exitface authored
This page is out of date. Refresh to see the latest.
View
4 lib/hirefire/backend.rb
@@ -27,6 +27,10 @@ def self.included(base)
end
end
+ if defined?(::Delayed::Backend::DataMapper::Job)
+ base.send(:include, HireFire::Backend::DelayedJob::DataMapper)
+ end
+
if defined?(::Delayed::Backend::Mongoid::Job)
base.send(:include, HireFire::Backend::DelayedJob::Mongoid)
end
View
1  lib/hirefire/backend/delayed_job.rb
@@ -6,6 +6,7 @@ module DelayedJob
autoload :ActiveRecord, 'hirefire/backend/delayed_job/active_record'
autoload :ActiveRecord2, 'hirefire/backend/delayed_job/active_record_2'
autoload :Mongoid, 'hirefire/backend/delayed_job/mongoid'
+ autoload :DataMapper, 'hirefire/backend/delayed_job/data_mapper'
end
end
end
View
30 lib/hirefire/backend/delayed_job/data_mapper.rb
@@ -0,0 +1,30 @@
+# encoding: utf-8
+
+module HireFire
+ module Backend
+ module DelayedJob
+ module DataMapper
+
+ ##
+ # 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.count(:failed_at => nil, :run_at.lte => Time.now.utc)
+ end
+
+ ##
+ # Counts the amount of jobs that are locked by a worker
+ # There is no other performant way to determine the amount
+ # of workers there currently are
+ #
+ # @return [Fixnum] the amount of (assumably working) workers
+ def working
+ ::Delayed::Job.count(:locked_by.not => nil)
+ end
+
+ end
+ end
+ end
+end
View
14 lib/hirefire/environment.rb
@@ -42,6 +42,20 @@ def self.included(base)
after_update 'self.class.environment.fire',
:unless => Proc.new { |job| job.failed_at.nil? }
end
+ elsif base.name == "Delayed::Backend::DataMapper::Job"
+ base.send :extend, HireFire::Environment::DelayedJob::ClassMethods
+
+ base.class_eval do
+ after :create do
+ self.class.hirefire_hire
+ end
+ after :destroy do
+ self.class.environment.fire
+ end
+ after :update do
+ self.class.environment.fire unless self.failed_at.nil?
+ end
+ end
end
Logger.message("#{ base.name } detected!")
View
9 lib/hirefire/initializer.rb
@@ -44,6 +44,15 @@ def self.initialize!
end
##
+ # If DelayedJob is using DataMapper, then include
+ # HireFire::Environment in to the DataMapper Delayed Job Backend
+ if defined?(::Delayed::Backend::DataMapper::Job)
+ ::Delayed::Backend::DataMapper::Job.
+ send(:include, HireFire::Environment).
+ send(:include, HireFire::Backend)
+ end
+
+ ##
# Load Delayed Job extensions, this will patch Delayed::Worker
# to implement the necessary hooks to invoke HireFire from
require 'hirefire/workers/delayed_job'
Something went wrong with that request. Please try again.