Class: PerfectSched::Engine

Inherits:
Object
  • Object
show all
Defined in:
lib/perfectsched/engine.rb

Instance Method Summary collapse

Constructor Details

#initialize(runner, config) ⇒ Engine

Returns a new instance of Engine.



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/perfectsched/engine.rb', line 22

def initialize(runner, config)
  @runner = runner

  @poll_interval = config[:poll_interval] || 1.0
  @log = config[:logger] || Logger.new(STDERR)

  @running_flag = BlockingFlag.new
  @finish_flag = BlockingFlag.new

  @scheds = PerfectSched.open(config)
end

Instance Method Details

#closeObject



59
60
61
62
# File 'lib/perfectsched/engine.rb', line 59

def close
  @scheds.close
  self
end

#joinObject



54
55
56
57
# File 'lib/perfectsched/engine.rb', line 54

def join
  @running_flag.wait while @running_flag.set?
  self
end

#runObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/perfectsched/engine.rb', line 34

def run
  @running_flag.set_region do
    until @finish_flag.set?
      task = @scheds.poll
      if task
        r = @runner.new(task)
        r.run
      else
        @finish_flag.wait(@poll_interval)
      end
    end
  end
  self
end

#shutdownObject



64
65
66
67
68
# File 'lib/perfectsched/engine.rb', line 64

def shutdown
  stop
  join
  close
end

#stopObject



49
50
51
52
# File 'lib/perfectsched/engine.rb', line 49

def stop
  @finish_flag.set!
  self
end