lib/pushpop/job.rb in pushpop-0.1.0 vs lib/pushpop/job.rb in pushpop-0.1.1

- old
+ new

@@ -13,23 +13,23 @@ end end attr_accessor :name - attr_accessor :every_duration + attr_accessor :period attr_accessor :every_options attr_accessor :steps def initialize(name=nil, &block) self.name = name || Pushpop.random_name self.steps = [] self.every_options = {} self.instance_eval(&block) end - def every(duration, options={}) - self.every_duration = duration + def every(period, options={}) + self.period = period self.every_options = options end def step(name=nil, plugin=nil, &block) if plugin @@ -46,11 +46,12 @@ def add_step(step) self.steps.push(step) end def schedule - Clockwork.manager.every(every_duration, name, every_options) do + raise 'Set job period via "every"' unless self.period + Clockwork.manager.every(period, name, every_options) do run end end def run @@ -76,9 +77,19 @@ [last_response, step_responses] end def method_missing(method, *args, &block) plugin_class = self.class.plugins[method.to_s] + + unless plugin_class + begin + Pushpop.load_plugin method.to_s + plugin_class = self.class.plugins[method.to_s] + raise "Plugin not loaded: #{method.to_s}" if plugin_class.nil? + rescue LoadError + Pushpop.logger.warn("Could not find plugin #{method.to_s}") + end + end name = args[0] plugin = method.to_s if plugin_class