Permalink
Browse files

Refactored the Sequel Job adapter. Added slight changes in the docs

  • Loading branch information...
1 parent 710c740 commit 8415499a2252c1b2250e52f16cb4594b5ee4d77c @antekpiechnik antekpiechnik committed Aug 12, 2010
Showing with 12 additions and 15 deletions.
  1. +1 −1 lib/navvy/job/data_mapper.rb
  2. +11 −14 lib/navvy/job/sequel.rb
@@ -27,7 +27,7 @@ class Job
# run
# @param [*] arguments optional arguments you want to pass to the method
#
- # @return [true, false]
+ # @return [Job, false]
def self.enqueue(object, method_name, *args)
options = {}
View
@@ -12,7 +12,7 @@ class Job < Sequel::Model
# run
# @param [*] arguments optional arguments you want to pass to the method
#
- # @return [true, false]
+ # @return [Job, false]
def self.enqueue(object, method_name, *args)
options = {}
@@ -21,16 +21,15 @@ def self.enqueue(object, method_name, *args)
args.pop if args.last.empty?
end
- insert(
+ Job[insert(
:object => object.to_s,
:method_name => method_name.to_s,
:arguments => args.to_yaml,
:priority => options[:priority] || 0,
:parent_id => options[:parent_id],
:run_at => options[:run_at] || Time.now,
:created_at => Time.now
- )
- order(:id.desc).first
+ )]
end
##
@@ -46,10 +45,9 @@ def self.enqueue(object, method_name, *args)
def self.next(limit = self.limit)
filter(
- (:run_at <= Time.now),
- {:failed_at => nil,
- :completed_at => nil}
- ).order(:priority.desc, :created_at).first(limit)
+ :failed_at => nil,
+ :completed_at => nil
+ ).where{:run_at <= Time.now}.order(:priority.desc, :created_at).first(limit)
end
##
@@ -84,9 +82,7 @@ def self.delete_all
# update_attributes call
def started
- update({
- :started_at => Time.now
- })
+ update(:started_at => Time.now)
end
##
@@ -99,10 +95,10 @@ def started
# update_attributes call
def completed(return_value = nil)
- update({
+ update(
:completed_at => Time.now,
:return => return_value
- })
+ )
end
##
@@ -132,7 +128,8 @@ def failed(message = nil)
def times_failed
i = parent_id || id
self.class.filter(
- ({:id => i} | {:parent_id => i}), ~{:failed_at => nil}
+ {:id => i} | {:parent_id => i},
+ ~{:failed_at => nil}
).count
end
end

0 comments on commit 8415499

Please sign in to comment.