Class: LaunchDarkly::Impl::RepeatingTask Private
- Inherits:
-
Object
- Object
- LaunchDarkly::Impl::RepeatingTask
- Defined in:
- lib/ldclient-rb/impl/repeating_task.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Instance Attribute Summary collapse
- #name ⇒ Object readonly private
Instance Method Summary collapse
-
#initialize(interval, start_delay, task, logger, name) ⇒ RepeatingTask
constructor
private
A new instance of RepeatingTask.
- #start ⇒ Object private
- #stop ⇒ Object private
Constructor Details
#initialize(interval, start_delay, task, logger, name) ⇒ RepeatingTask
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of RepeatingTask.
10 11 12 13 14 15 16 17 18 |
# File 'lib/ldclient-rb/impl/repeating_task.rb', line 10 def initialize(interval, start_delay, task, logger, name) @interval = interval @start_delay = start_delay @task = task @logger = logger @stopped = Concurrent::AtomicBoolean.new(false) @worker = nil @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
8 9 10 |
# File 'lib/ldclient-rb/impl/repeating_task.rb', line 8 def name @name end |
Instance Method Details
#start ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ldclient-rb/impl/repeating_task.rb', line 20 def start @worker = Thread.new do sleep(@start_delay) unless @start_delay.nil? || @start_delay == 0 until @stopped.value do started_at = Time.now begin @task.call rescue => e Impl::Util.log_exception(@logger, "Uncaught exception from repeating task", e) end delta = @interval - (Time.now - started_at) if delta > 0 sleep(delta) end end end @worker.name = @name end |
#stop ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
41 42 43 44 45 46 47 48 |
# File 'lib/ldclient-rb/impl/repeating_task.rb', line 41 def stop if @stopped.make_true if @worker && @worker.alive? && @worker != Thread.current @worker.run # causes the thread to wake up if it's currently in a sleep @worker.join end end end |