Module: Exekutor::Internal::Executable
- Included in:
- Executor, Listener, Provider, StatusServer, Worker
- Defined in:
- lib/exekutor/internal/executable.rb
Overview
Mixin for an executable
Constant Summary collapse
- STATES =
Possible states
%i[pending started stopped crashed killed].freeze
Instance Method Summary collapse
-
#consecutive_errors ⇒ Concurrent::AtomicFixnum
The number of consecutive errors that have occurred.
-
#initialize ⇒ Object
Initializes the internal variables.
-
#restart_delay ⇒ Float
Calculates an exponential delay based on #consecutive_errors.
-
#running? ⇒ Boolean
Whether the state equals
:started
. -
#state ⇒ :pending, ...
The state of this executable.
Instance Method Details
#consecutive_errors ⇒ Concurrent::AtomicFixnum
Returns the number of consecutive errors that have occurred.
35 36 37 |
# File 'lib/exekutor/internal/executable.rb', line 35 def consecutive_errors @consecutive_errors end |
#initialize ⇒ Object
Initializes the internal variables
13 14 15 16 |
# File 'lib/exekutor/internal/executable.rb', line 13 def initialize @state = Concurrent::AtomicReference.new(:pending) @consecutive_errors = Concurrent::AtomicFixnum.new(0) end |
#restart_delay ⇒ Float
Calculates an exponential delay based on #consecutive_errors. The delay ranges from 10 seconds on the first error to 10 minutes from the 13th error on.
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/exekutor/internal/executable.rb', line 42 def restart_delay if @consecutive_errors.value > 150 error = SystemExit.new "Too many consecutive errors (#{@consecutive_errors.value})" Exekutor.on_fatal_error error raise error end delay = (9 + (@consecutive_errors.value**2.5)) delay += delay * (rand(-5..5) / 100.0) delay.clamp(10.0, 600.0) end |
#running? ⇒ Boolean
Returns whether the state equals :started
.
30 31 32 |
# File 'lib/exekutor/internal/executable.rb', line 30 def running? @state.get == :started end |
#state ⇒ :pending, ...
The state of this executable. Possible values are:
-
:pending
the executable has not been started yet -
:started
the executable has started -
:stopped
the executable has stopped -
:crashed
the executable has crashed -
:killed
the executable was killed
25 26 27 |
# File 'lib/exekutor/internal/executable.rb', line 25 def state @state.get end |