Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactored the DataMapper Job adapter

  • Loading branch information...
commit 710c74080f73d7c0174d698afa2172605e0e00fa 1 parent 12db7c3
@antekpiechnik antekpiechnik authored
View
2  Gemfile
@@ -5,7 +5,7 @@ group :active_record do
end
group :data_mapper do
- gem 'dm-core', '>= 0.10.2'
+ gem 'dm-core', '>= 1.0.0'
gem 'dm-sqlite-adapter'
gem 'dm-migrations'
end
View
18 lib/navvy/job/data_mapper.rb
@@ -36,8 +36,7 @@ def self.enqueue(object, method_name, *args)
args.pop if args.last.empty?
end
- new_job = self.new
- new_job.attributes = {
+ new_job = Job.create(
:object => object.to_s,
:method_name => method_name.to_s,
:arguments => args.to_yaml,
@@ -45,9 +44,7 @@ def self.enqueue(object, method_name, *args)
:parent_id => options[:parent_id],
:run_at => options[:run_at] || Time.now,
:created_at => Time.now
- }
- new_job.save
- new_job
+ )
end
##
@@ -92,7 +89,7 @@ def self.cleanup
# @return [true, false] deleted?
def self.delete_all
- Navvy::Job.all.destroy
+ Navvy::Job.destroy
end
##
@@ -102,9 +99,7 @@ def self.delete_all
# update_attributes call
def started
- update({
- :started_at => Time.now
- })
+ update(:started_at => Time.now)
end
##
@@ -150,9 +145,8 @@ def failed(message = nil)
def times_failed
i = parent_id || id
- self.class.all(
- :conditions => ["(`id` = ? OR `parent_id` = ?) AND `failed_at` IS NOT NULL", i, i]
- ).count
+ not_failed = self.class.all(:failed_at.not => nil)
+ (not_failed.all(:id => i) | not_failed.all(:parent_id => i)).count
end
end
end
View
1  spec/setup/data_mapper.rb
@@ -1,3 +1,4 @@
require File.expand_path(File.dirname(__FILE__) + '/../../lib/navvy/job/data_mapper')
DataMapper.setup(:default, "sqlite3:///tmp/navvy_test.sqlite")
+DataMapper.finalize
Navvy::Job.auto_migrate!
Please sign in to comment.
Something went wrong with that request. Please try again.