module Ecoportal module API class V1 class Job class Awaiter module StatusFrequency include Common::Client::TimeOut DELAY_STATUS_CHECK = 4 MIN_STATUS_CHECK = 2 private def status_checked? @status_checked || false end def status_check_in(pending, timeout_in:) # first check to be faster unless status_checked? @status_checked = true unless pending.zero? # <= increases job status requests! return min_delay_status_check end return default_delay_status_check if around_min_throughput? eta = eta_for(pending, approach: :optimistic) check_in_max = [eta, timeout_in].min * 0.90 check_in_best = check_in_max / 2.0 default_5 = default_delay_status_check * 5 top_check = [default_5, check_in_best].min.ceil [top_check, min_delay_status_check].max end def default_delay_status_check self.class::DELAY_STATUS_CHECK end def min_delay_status_check self.class::MIN_STATUS_CHECK end end end end end end end