Module: Brine::Performing
- Included in:
- Brine
- Defined in:
- lib/brine/performing.rb
Overview
Support 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 active Performer instance.
-
#performer ⇒ Performer, #perform
Expose the currently active Performer as a property.
-
#poll_for(seconds, interval = poll_interval_seconds) ⇒ Object
Retry the provided block for the specified period.
-
#poll_interval_seconds ⇒ Number
Determine the number of seconds between polling attempts.
-
#reset_performer ⇒ Performer, #perform
Reset the Performer instance to the default implementation.
-
#retrieve_duration(duration) ⇒ Number
Retrieve the duration in seconds for the given handle.
Instance Method Details
#collect_actions ⇒ Object
Begin collecting, rather than immediately performing, actions.
92 93 94 |
# File 'lib/brine/performing.rb', line 92 def collect_actions @performer = CollectingPerformer.new end |
#perform(&actions) ⇒ Object
Pass the actions to the active Performer instance.
85 86 87 |
# File 'lib/brine/performing.rb', line 85 def perform(&actions) performer.perform(actions) end |
#performer ⇒ Performer, #perform
Expose the currently active Performer as a property.
The default implementation will be wired as needed upon first access.
67 68 69 |
# File 'lib/brine/performing.rb', line 67 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.
121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/brine/performing.rb', line 121 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
Determine the number of seconds between polling attempts.
This can be provided by the ‘BRINE_POLL_INTERVAL_SECONDS` environment variable (defaults to `0.5`).
104 105 106 |
# File 'lib/brine/performing.rb', line 104 def poll_interval_seconds ENV['BRINE_POLL_INTERVAL_SECONDS'] || 0.25 end |
#reset_performer ⇒ Performer, #perform
Reset the Performer instance to the default implementation.
76 77 78 |
# File 'lib/brine/performing.rb', line 76 def reset_performer @performer = ImmediatePerformer.new end |
#retrieve_duration(duration) ⇒ Number
Retrieve the duration in seconds for the given handle.
Currently this only supports values provided through environment variables of the format BRINE_DURATION_SECONDS_handle.
144 145 146 147 148 149 150 |
# File 'lib/brine/performing.rb', line 144 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 |