lib/resque-timeframe/timeframe.rb in resque-timeframe-0.1.0 vs lib/resque-timeframe/timeframe.rb in resque-timeframe-0.2.0
- old
+ new
@@ -9,15 +9,26 @@
def week
WEEK
end
def settings
- @options ||= WEEK.inject({:default => true}) {|c,v| c.merge({v => true})}
+ @options ||= WEEK.inject({:default => true, :recurrent => 60}) {|c,v| c.merge({v => true})}
end
- def timeframe(options={})
- settings.merge!(options)
+ def timeframe(options = {})
+ options.map do |param,value|
+ case param
+ when Array
+ param.map {|k| timeframe({k => value}) }
+ when String
+ timeframe({param.to_sym => value})
+ when Symbol
+ settings.merge!({param => value})
+ else
+ #
+ end
+ end
end
def allowed_at?(weekday)
case settings[weekday]
when Range
@@ -50,10 +61,14 @@
time_at(0)..time_at(24)
end
end
def before_perform_timeframe(*args)
- raise Resque::Job::DontPerform unless allowed_at?(week[Time.new.wday])
+ unless allowed_at?(week[Time.new.wday])
+ Resque.enqueue_in(settings[:recurrent], self, *args) if settings[:recurrent]
+
+ raise Resque::Job::DontPerform
+ end
end
end
class TimeframedJob