Class: Flydata::Helper::Scheduler
- Inherits:
-
Object
- Object
- Flydata::Helper::Scheduler
- 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
- DEBUG_DUMP_INTERVAL =
seconds
60.0
Instance Attribute Summary collapse
-
#helper_conf ⇒ Object
readonly
Returns the value of attribute helper_conf.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
Instance Method Summary collapse
-
#initialize(helper_conf, server) ⇒ Scheduler
constructor
A new instance of Scheduler.
- #join ⇒ Object
- #reload(helper_conf) ⇒ Object
- #run ⇒ Object
-
#running? ⇒ Boolean
For debug.
- #scheduled_actions ⇒ Object
- #shutdown ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
- #wake ⇒ Object
Constructor Details
#initialize(helper_conf, server) ⇒ Scheduler
Returns a new instance of Scheduler.
12 13 14 15 16 17 |
# File 'lib/flydata/helper/scheduler.rb', line 12 def initialize(helper_conf, server) @stop_flag = ServerEngine::BlockingFlag.new @server = server self.logger = server.logger reload(helper_conf) end |
Instance Attribute Details
#helper_conf ⇒ Object (readonly)
Returns the value of attribute helper_conf.
19 20 21 |
# File 'lib/flydata/helper/scheduler.rb', line 19 def helper_conf @helper_conf end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
19 20 21 |
# File 'lib/flydata/helper/scheduler.rb', line 19 def server @server end |
Instance Method Details
#join ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/flydata/helper/scheduler.rb', line 61 def join log_debug("join") stop if @thread @thread.join @thread = nil end end |
#reload(helper_conf) ⇒ Object
48 49 50 51 52 |
# File 'lib/flydata/helper/scheduler.rb', line 48 def reload(helper_conf) log_info("reload") @helper_conf = helper_conf update_scheduled_actions end |
#run ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/flydata/helper/scheduler.rb', line 27 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
72 73 74 |
# File 'lib/flydata/helper/scheduler.rb', line 72 def running? !!(@thread and @thread.alive?) end |
#scheduled_actions ⇒ Object
76 77 78 |
# File 'lib/flydata/helper/scheduler.rb', line 76 def scheduled_actions @scheduled_actions.dup end |
#shutdown ⇒ Object
54 55 56 57 58 59 |
# File 'lib/flydata/helper/scheduler.rb', line 54 def shutdown log_info("shutdown") stop join self end |
#start ⇒ Object
21 22 23 24 25 |
# File 'lib/flydata/helper/scheduler.rb', line 21 def start log_info("start") @thread = Thread.new(&method(:run)) self end |
#stop ⇒ Object
43 44 45 46 |
# File 'lib/flydata/helper/scheduler.rb', line 43 def stop log_info("stop") @stop_flag.set! end |
#wake ⇒ Object
38 39 40 41 |
# File 'lib/flydata/helper/scheduler.rb', line 38 def wake log_debug("wake") @stop_flag.reset! end |