Skip to content

Extract exponential backoff logic from await/recover into shared helper #371

Description

@VasilevNStas

Extract exponential backoff logic from await/recover into shared helper

Severity: MEDIUM (Maintainability)

Location

lib/baza-rb.rb:627-629 and 651-653:

seconds = @pause * (2**attempt)
sleep(seconds) unless ENV['RACK_ENV'] == 'test'

Duplicated in await and recover. Similar hardcoded logic in download (sleep(2)).

Problem

Backoff logic is scattered across three methods with slight variations:

  • await and recover: @pause * (2**attempt) with ENV guard
  • download: sleep(2) — hardcoded, no exponential backoff

Changing backoff policy requires editing 3+ places.

Recommended fix

def backoff(attempt)
  seconds = @pause * (2**attempt)
  @loog.info("Sleeping for #{seconds}s (attempt no.#{attempt})...")
  sleep(seconds) unless ENV['RACK_ENV'] == 'test'
  seconds
end

Use in await, recover, and (with different params) in download.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions