Class: Kybus::DRY::Daemon
- Inherits:
-
Object
- Object
- Kybus::DRY::Daemon
- Includes:
- Logger
- Defined in:
- lib/kybus/dry/daemon.rb
Overview
Use this for running tasks that will be looping by only sending a lambda TODO: Improve this class.
-
Add a maechanism for killing the process
-
Add a function to test how many threads are alive
-
Make it testable
-
Add unit tests
Instance Method Summary collapse
-
#await ⇒ Object
:nocov: #.
-
#initialize(wait_time, attach, retry_on_failure = false, &block) ⇒ Daemon
constructor
A new instance of Daemon.
- #run ⇒ Object
- #task ⇒ Object
Constructor Details
#initialize(wait_time, attach, retry_on_failure = false, &block) ⇒ Daemon
Returns a new instance of Daemon.
16 17 18 19 20 21 22 |
# File 'lib/kybus/dry/daemon.rb', line 16 def initialize(wait_time, attach, retry_on_failure = false, &block) @proc = block @wait_time = wait_time @attach = attach @retry_on_failure = retry_on_failure @finish = false end |
Instance Method Details
#await ⇒ Object
:nocov: #
51 52 53 |
# File 'lib/kybus/dry/daemon.rb', line 51 def await @thread&.join end |
#run ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/kybus/dry/daemon.rb', line 40 def run if @attach task else # :nocov: # @thread = Thread.new { task } # :nocov: # end end |
#task ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/kybus/dry/daemon.rb', line 24 def task log_info 'starting daemon' loop do begin @proc.call rescue StandardError => e raise unless @retry_on_failure # :nocov: # log_error('Unexpected error', error: e) # :nocov: # end sleep(@wait_time) end end |