Class: Flydata::Helper::Scheduler

Inherits:
Object
  • Object
show all
Includes:
FlydataCore::Logger
Defined in:
lib/flydata/helper/scheduler.rb

Constant Summary collapse

RUN_INTERVAL =

second

1.0
RUN_GC_INTERVAL =

seconds

60.0 * 5

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(helper_conf, server) ⇒ Scheduler

Returns a new instance of Scheduler.


11
12
13
14
15
16
# File 'lib/flydata/helper/scheduler.rb', line 11

def initialize(helper_conf, server)
  @stop_flag = ServerEngine::BlockingFlag.new
  @server = server
  self.logger = server.logger
  reload(helper_conf)
end

Instance Attribute Details

#helper_confObject (readonly)

Returns the value of attribute helper_conf.


18
19
20
# File 'lib/flydata/helper/scheduler.rb', line 18

def helper_conf
  @helper_conf
end

#serverObject (readonly)

Returns the value of attribute server.


18
19
20
# File 'lib/flydata/helper/scheduler.rb', line 18

def server
  @server
end

Instance Method Details

#joinObject


60
61
62
63
64
65
66
67
# File 'lib/flydata/helper/scheduler.rb', line 60

def join
  log_debug("join")
  stop
  if @thread
    @thread.join
    @thread = nil
  end
end

#reload(helper_conf) ⇒ Object


47
48
49
50
51
# File 'lib/flydata/helper/scheduler.rb', line 47

def reload(helper_conf)
  log_info("reload")
  @helper_conf = helper_conf
  update_scheduled_actions
end

#runObject


26
27
28
29
30
31
32
33
34
35
# File 'lib/flydata/helper/scheduler.rb', line 26

def run
  until @stop_flag.set?
    run_once
  end
rescue => e
  log_error("unexpected error during running. error:#{e}\n" + e.backtrace.join("\n"))
  retry unless @stop_flag.wait_for_set(5.0)
ensure
  log_debug("finish running")
end

#running?Boolean

For debug

Returns:

  • (Boolean)

71
72
73
# File 'lib/flydata/helper/scheduler.rb', line 71

def running?
  !!(@thread and @thread.alive?)
end

#scheduled_actionsObject


75
76
77
# File 'lib/flydata/helper/scheduler.rb', line 75

def scheduled_actions
  @scheduled_actions.dup
end

#shutdownObject


53
54
55
56
57
58
# File 'lib/flydata/helper/scheduler.rb', line 53

def shutdown
  log_info("shutdown")
  stop
  join
  self
end

#startObject


20
21
22
23
24
# File 'lib/flydata/helper/scheduler.rb', line 20

def start
  log_info("start")
  @thread = Thread.new(&method(:run))
  self
end

#stopObject


42
43
44
45
# File 'lib/flydata/helper/scheduler.rb', line 42

def stop
  log_info("stop")
  @stop_flag.set!
end

#wakeObject


37
38
39
40
# File 'lib/flydata/helper/scheduler.rb', line 37

def wake
  log_debug("wake")
  @stop_flag.reset!
end