Skip to content

Fixed to work DataMapper 1.2 #8

Merged
merged 4 commits into from Jan 13, 2012
View
4 delayed_job_data_mapper.gemspec
@@ -14,8 +14,8 @@ Gem::Specification.new do |s|
s.require_paths = ['lib']
s.test_files = Dir.glob('spec/**/*')
- s.add_runtime_dependency 'delayed_job', '3.0.0.pre2'
- s.add_runtime_dependency 'data_mapper'
+ s.add_runtime_dependency 'delayed_job', '~> 3.0'
+ s.add_runtime_dependency 'dm-core', '~> 1.0'
s.add_runtime_dependency 'i18n'
s.add_runtime_dependency 'tzinfo'
s.add_development_dependency 'rake'
View
4 lib/delayed/backend/data_mapper.rb
@@ -30,7 +30,7 @@ def self.find_available(worker_name, limit = 5, max_run_time = Worker.max_run_ti
simple_conditions[:priority.gte] = Worker.min_priority if Worker.min_priority
simple_conditions[:priority.lte] = Worker.max_priority if Worker.max_priority
simple_conditions[:queue] = Worker.queues if Worker.queues.any?
- lockable = (all(:run_at.lte => db_time_now) & (all(:locked_at => nil) | all(:locked_at.lt => db_time_now - max_run_time)) | all(:locked_by => worker_name)) & all(:failed_at => nil)
+ lockable = (all(:run_at.lte => db_time_now) & (all(:locked_at => nil) | all(:locked_at.lt => db_time_now - max_run_time.to_i)) | all(:locked_by => worker_name)) & all(:failed_at => nil)
lockable.all(simple_conditions)
end
@@ -48,7 +48,7 @@ def lock_exclusively!(max_run_time, worker = worker_name)
# DM doesn't give us the number of rows affected by a collection update
# so we have to circumvent some niceness in DM::Collection here
collection = if locked_by != worker
- (self.class.all(:id => id) & (self.class.all(:locked_at => nil) | self.class.all(:locked_at.lt => now - max_run_time)) & self.class.all(:run_at.lte => now))
+ (self.class.all(:id => id) & (self.class.all(:locked_at => nil) | self.class.all(:locked_at.lt => now - max_run_time.to_i)) & self.class.all(:run_at.lte => now))
else
self.class.all(:id => id, :locked_by => worker)
end
View
8 lib/delayed/serialization/data_mapper.rb
@@ -5,15 +5,19 @@
def self.yaml_new(klass, tag, val)
begin
- klass.get!(val['attributes']['id'])
+ primary_keys = klass.properties.select { |p| p.key? }
+ key_names = primary_keys.map { |p| p.name.to_s }
+ klass.get!(*key_names.map { |k| val[k] })
rescue DataMapper::ObjectNotFoundError
raise Delayed::DeserializationError
end
end
def to_yaml_properties
- ['@attributes']
+ primary_keys = self.class.properties.select { |p| p.key? }
+ primary_keys.map { |p| "@#{p.name}" }
end
+
end
else
DataMapper::Resource.class_eval do
View
2 lib/delayed_job_data_mapper.rb
@@ -1,5 +1,5 @@
# encoding: utf-8
-require 'data_mapper'
+require 'dm-core'
require 'delayed_job'
require 'delayed/serialization/data_mapper'
require 'delayed/backend/data_mapper'
Something went wrong with that request. Please try again.