Class: PerfectSched::Application::Base

Inherits:
Runner
  • Object
show all
Defined in:
lib/perfectsched/application/base.rb

Instance Attribute Summary collapse

Attributes inherited from Runner

#task

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Runner

#schedules

Constructor Details

#initialize(task) ⇒ Base

Returns a new instance of Base.



34
35
36
37
# File 'lib/perfectsched/application/base.rb', line 34

def initialize(task)
  super
  @decider = self.class.decider.new(self)
end

Instance Attribute Details

#deciderObject (readonly)

Returns the value of attribute decider.



39
40
41
# File 'lib/perfectsched/application/base.rb', line 39

def decider
  @decider
end

Class Method Details

.deciderObject



23
24
25
# File 'lib/perfectsched/application/base.rb', line 23

def self.decider
  DefaultDecider
end

.decider=(decider_klass) ⇒ Object



27
28
29
30
31
32
# File 'lib/perfectsched/application/base.rb', line 27

def self.decider=(decider_klass)
  (class<<self;self;end).instance_eval do
    self.__send__(:define_method, :decider) { decider_klass }
  end
  decider_klass
end

Instance Method Details

#after_performObject

def perform end



61
62
# File 'lib/perfectsched/application/base.rb', line 61

def after_perform
end

#before_performObject



54
55
56
# File 'lib/perfectsched/application/base.rb', line 54

def before_perform
  true
end

#decide!(type, option = {}) ⇒ Object



64
65
66
# File 'lib/perfectsched/application/base.rb', line 64

def decide!(type, option={})
  @decider.decide!(type, option)
end

#runObject



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/perfectsched/application/base.rb', line 41

def run
  begin
    return unless before_perform
    begin
      perform
    ensure
      after_perform
    end
  rescue
    decide! :unexpected_error_raised, :error=>$!
  end
end