Module: Urge::ClassMethods
- Defined in:
- lib/urge.rb
Instance Method Summary collapse
- #urge_all_schedules ⇒ Object
-
#urge_attr_name(name) ⇒ Object
private.
-
#urge_logger ⇒ Object
def run_all( name ) now = DateTime.now logger.debug “run_all.
- #urge_schedule(name, options = {}) ⇒ Object
- #urge_schedules ⇒ Object
Instance Method Details
#urge_all_schedules ⇒ Object
60 61 62 |
# File 'lib/urge.rb', line 60 def urge_all_schedules @@urge_per_class_schedules end |
#urge_attr_name(name) ⇒ Object
private
66 67 68 69 |
# File 'lib/urge.rb', line 66 def urge_attr_name( name ) raise 'Non existent schedule name' unless urge_schedules[name] urge_schedules[name][:timestamp_name] end |
#urge_logger ⇒ Object
def run_all( name )
now = DateTime.now
logger.debug "run_all. Time now: #{now}"
ready_to_run( name, now ).each do |task|
logger.debug "Task of class #{task.class.name} named: #{name} is about to be run"
task.run( name )
end
end
def inspect_all( name )
now = DateTime.now
tasks = ready_to_run( name, now )
logger.info "inspect_queue. Time now: #{now}. The following #{tasks.size} tasks are ready to run"
tasks.each { |task| logger.info task.inspect }
tasks
end
27 28 29 |
# File 'lib/urge.rb', line 27 def urge_logger @@urge_logger ||= Logging.logger[self] end |
#urge_schedule(name, options = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/urge.rb', line 31 def urge_schedule( name, = {} ) urge_logger.info "Defining schedule: #{name}. Options: #{}. Class: #{self.name}" # Warn if a schedule with this name already exists, but don't bail out. # It's not necessarily an error. Rails autoloading classes is an example where it's not... urge_logger.warn "A schedule with this name already exists. Old options: #{urge_schedules[name]}" if urge_schedules[name] # NEW. Set defaults. The name pf the action metod is the same as the name of the schedule, and the name of the timestamp # attribute is likewise, but with _at appended. # For example, if the schedule name is 'check_credit', the signature of the action method - unless overridden - is # expected to be # def check_credit( options ) # end # The timestamp name - unless set explicitly - is check_credit_at [:timestamp_name] ||= "#{name}_at" [:action] ||= name urge_schedules[name] = end |
#urge_schedules ⇒ Object
55 56 57 58 |
# File 'lib/urge.rb', line 55 def urge_schedules @@urge_per_class_schedules ||= {} @@urge_per_class_schedules[self.name] ||= {} end |