Class: Aspera::Transfer::Resumer
- Inherits:
-
Object
- Object
- Aspera::Transfer::Resumer
- Defined in:
- lib/aspera/transfer/resumer.rb
Overview
Implements a simple resume policy
Instance Method Summary collapse
-
#execute_with_resume ⇒ Object
Calls block a number of times (resumes) until success or limit reached This is re-entrant, one resumer can handle multiple transfers in //.
-
#initialize(iter_max: 7, sleep_initial: 2, sleep_factor: 2, sleep_max: 60) ⇒ Resumer
constructor
A new instance of Resumer.
Constructor Details
#initialize(iter_max: 7, sleep_initial: 2, sleep_factor: 2, sleep_max: 60) ⇒ Resumer
Returns a new instance of Resumer.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/aspera/transfer/resumer.rb', line 18 def initialize( iter_max: 7, sleep_initial: 2, sleep_factor: 2, sleep_max: 60 ) Aspera.assert_type(iter_max, Integer) { 'iter_max' } @iter_max = iter_max Aspera.assert_type(sleep_initial, Integer) { 'sleep_initial' } @sleep_initial = sleep_initial Aspera.assert_type(sleep_factor, Integer) { 'sleep_factor' } @sleep_factor = sleep_factor Aspera.assert_type(sleep_max, Integer) { 'sleep_max' } @sleep_max = sleep_max end |
Instance Method Details
#execute_with_resume ⇒ Object
Calls block a number of times (resumes) until success or limit reached This is re-entrant, one resumer can handle multiple transfers in //
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/aspera/transfer/resumer.rb', line 38 def execute_with_resume Aspera.assert(block_given?, 'block required for execute_with_resume') # maximum of retry remaining_resumes = @iter_max sleep_seconds = @sleep_initial Log.log.debug { "retries=#{remaining_resumes}" } # try to send the file until ascp is successful loop do Log.log.debug('Starting task execution') begin # Call provided block: execute transfer yield # Exit retry loop if success break rescue Error => e Log.log.warn { "An error occurred during task: #{e.}" } Log.log.debug { "Retryable ? #{e.retryable?}" } # do not retry non-retryable raise unless e.retryable? # exit if we exceed the max number of retry Aspera.assert(remaining_resumes > 0, type: Error) { "Maximum number of retry reached: #{@iter_max}" } end # take this retry in account remaining_resumes -= 1 Log.log.warn { "Resuming in #{sleep_seconds} seconds (retry left:#{remaining_resumes})" } # wait a bit before retrying, maybe network condition will be better sleep(sleep_seconds) # increase retry period sleep_seconds *= @sleep_factor # cap value sleep_seconds = @sleep_max if sleep_seconds > @sleep_max end end |