Class: BitGirder::Concurrent::Retry
- Inherits:
-
BitGirder::Core::BitGirderClass
- Object
- BitGirder::Core::BitGirderClass
- BitGirder::Concurrent::Retry
- Defined in:
- lib/bitgirder/concurrent.rb
Defined Under Namespace
Classes: Builder
Constant Summary
Constants included from BitGirder::Core::BitGirderMethods
BitGirder::Core::BitGirderMethods::PARAM_TYPE_ARG, BitGirder::Core::BitGirderMethods::PARAM_TYPE_ENVVAR, BitGirder::Core::BitGirderMethods::PARAM_TYPE_KEY
Instance Attribute Summary collapse
-
#attempt ⇒ Object
readonly
Returns the value of attribute attempt.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
Class Method Summary collapse
Instance Method Summary collapse
- #complete(res = nil) ⇒ Object
- #fail_attempt(err) ⇒ Object
-
#initialize(*argv) {|@bldr| ... } ⇒ Retry
constructor
A new instance of Retry.
- #run ⇒ Object
- #seed_secs ⇒ Object
Methods included from BitGirder::Core::BitGirderMethods
argv_to_argh, check_fail_prefix, class_name_to_sym, code, compares_to, console, ext_to_class_name, ext_to_sym, has_env, has_key, has_keys, nonnegative, not_nil, positive, raisef, set_from_key, set_var, split_argv, sym_to_cli_switch, sym_to_ext_id, to_bool, unpack_argv_array, unpack_argv_hash, warn
Methods included from BitGirder::Core::BitGirderStructure
Constructor Details
#initialize(*argv) {|@bldr| ... } ⇒ Retry
Returns a new instance of Retry.
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/bitgirder/concurrent.rb', line 220 def initialize( *argv ) super BitGirder::Concurrent.require_em @bldr = Builder.new yield @bldr if block_given? @bldr.freeze [ :retries, :seed_secs, :retry_on ].each do |m| raise ":#{m} not set" unless @bldr.instance_variable_get( :"@#{m}" ) end if @bldr.action || @bldr.async_action if @bldr.action && @bldr.async_action raise "Both a synchronous and asynchronous action were set" end else raise "Neither :action nor :async_action was set" end @attempt = 0 end |
Instance Attribute Details
#attempt ⇒ Object (readonly)
Returns the value of attribute attempt.
218 219 220 |
# File 'lib/bitgirder/concurrent.rb', line 218 def attempt @attempt end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
218 219 220 |
# File 'lib/bitgirder/concurrent.rb', line 218 def start_time @start_time end |
Class Method Details
Instance Method Details
#complete(res = nil) ⇒ Object
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 |
# File 'lib/bitgirder/concurrent.rb', line 309 def complete( res = nil ) if block_given? if res == nil begin complete_final( yield ) # okay for yield to return nil rescue Exception => e action_failed( e ) end else raise "Block passed to complete with non-nil result: #{res}" end else complete_final( res ) end end |
#fail_attempt(err) ⇒ Object
328 329 330 |
# File 'lib/bitgirder/concurrent.rb', line 328 def fail_attempt( err ) complete { raise err } end |
#run ⇒ Object
349 350 351 352 353 354 355 356 357 |
# File 'lib/bitgirder/concurrent.rb', line 349 def run if @start_time raise "run() already called" else @start_time = Time.now run_attempt end end |
#seed_secs ⇒ Object
245 246 247 |
# File 'lib/bitgirder/concurrent.rb', line 245 def seed_secs @bldr.seed_secs end |