Module: Brine::Performing
- Included in:
- Brine
- Defined in:
- lib/brine/performing.rb
Overview
A module supporting either immediate or defered evaluation of logic.
Defined Under Namespace
Classes: CollectingPerformer, ImmediatePerformer
Instance Method Summary collapse
-
#collect_actions ⇒ Object
Begin collecting, rather than immediately performing, actions.
-
#perform(&actions) ⇒ Object
Pass the actions to the current Performer instance.
-
#performer ⇒ Performer, #perform
The currently active Performer instance exposed as a property.
-
#poll_for(seconds, interval = poll_interval_seconds) ⇒ Object
Retry the provided block for the specified period.
-
#poll_interval_seconds ⇒ Number
The number of seconds between polling attempts.
-
#reset_performer ⇒ Performer, #perform
Reset the Performer instance to the default implementation.
-
#retrieve_duration(duration) ⇒ Number
The duration in seconds for the given handle.
Instance Method Details
#collect_actions ⇒ Object
Begin collecting, rather than immediately performing, actions.
93 94 95 |
# File 'lib/brine/performing.rb', line 93 def collect_actions @performer = CollectingPerformer.new end |
#perform(&actions) ⇒ Object
Pass the actions to the current Performer instance.
86 87 88 |
# File 'lib/brine/performing.rb', line 86 def perform(&actions) performer.perform(actions) end |
#performer ⇒ Performer, #perform
The currently active Performer instance exposed as a property.
The default implementation will be wired as needed upon first access.
68 69 70 |
# File 'lib/brine/performing.rb', line 68 def performer @performer || reset_performer end |
#poll_for(seconds, interval = poll_interval_seconds) ⇒ Object
Retry the provided block for the specified period.
If the provided block is evaluated successfully the result will be returned, if any exception is thrown it will be retried until the period elapses.
122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/brine/performing.rb', line 122 def poll_for(seconds, interval=poll_interval_seconds) failure = nil quit = Time.now + seconds while (Time.now < quit) begin return yield rescue Exception => ex failure = ex sleep interval end end raise failure end |
#poll_interval_seconds ⇒ Number
The number of seconds between polling attempts.
Can be provided by the ‘BRINE_POLL_INTERVAL_SECONDS` environment variable. Defaults to `0.5`.
105 106 107 |
# File 'lib/brine/performing.rb', line 105 def poll_interval_seconds ENV['BRINE_POLL_INTERVAL_SECONDS'] || 0.25 end |
#reset_performer ⇒ Performer, #perform
Reset the Performer instance to the default implementation.
77 78 79 |
# File 'lib/brine/performing.rb', line 77 def reset_performer @performer = ImmediatePerformer.new end |
#retrieve_duration(duration) ⇒ Number
The duration in seconds for the given handle.
Currently this only supports values provided through environment variables of the format BRINE_DURATION_SECONDS_handle.
@param duration The handle/name of the duration whose length should be returned.
145 146 147 148 149 150 151 |
# File 'lib/brine/performing.rb', line 145 def retrieve_duration(duration) if ENV["BRINE_DURATION_SECONDS_#{duration}"] ENV["BRINE_DURATION_SECONDS_#{duration}"].to_f else STDERR.puts("Duration #{duration} not defined") end end |