Module: Powcloud::Insurance::AgentScheduler

Included in:
Agent
Defined in:
lib/powcloud/insurance/agent_scheduler.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#after(seconds) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/powcloud/insurance/agent_scheduler.rb', line 33

def after(seconds)
  if block_given?
    EM.add_timer(seconds) do
      yield
    end
  end
end

#every(seconds) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/powcloud/insurance/agent_scheduler.rb', line 25

def every(seconds)
  if block_given?
    EM.add_periodic_timer(seconds) do
      yield
    end
  end
end

#schedulerObject

Plain sugar.



21
22
23
# File 'lib/powcloud/insurance/agent_scheduler.rb', line 21

def scheduler
  yield if block_given?
end

#start_schedulerObject

Non-blocking.



13
14
15
16
17
18
# File 'lib/powcloud/insurance/agent_scheduler.rb', line 13

def start_scheduler
  if self.class.class_variable_defined? :@@scheduler_block
    block = self.class.send(:class_variable_get, :@@scheduler_block)
    instance_eval(&block) if block # TODO: class_eval?
  end
end