MCPcopy Create free account
hub / github.com/dwavesystems/dwave-cloud-client / _poll_using_backoff

Method _poll_using_backoff

dwave/cloud/client/base.py:1599–1625  ·  view source on GitHub ↗
(self, future: Future)

Source from the content-addressed store, hash-verified

1597 raise RuntimeError("unexpected polling strategy")
1598
1599 def _poll_using_backoff(self, future: Future) -> None:
1600 if future._poll_backoff is None:
1601 # on first poll, start with minimal back-off
1602 future._poll_backoff = self.config.polling_schedule.backoff_min
1603 else:
1604 # on subsequent polls, do exponential back-off, clipped to a range
1605 future._poll_backoff = \
1606 max(self.config.polling_schedule.backoff_min,
1607 min(future._poll_backoff * self.config.polling_schedule.backoff_base,
1608 self.config.polling_schedule.backoff_max))
1609
1610 # for poll priority we use timestamp of next scheduled poll
1611 at = time.time() + future._poll_backoff
1612
1613 now = utcnow()
1614 future_age = (now - future.time_created).total_seconds()
1615 logger.debug("Polling scheduled at %.2f with %.2f sec new back-off for: %s (future's age: %.2f sec)",
1616 at, future._poll_backoff, future.id, future_age)
1617
1618 # don't enqueue for next poll if polling_timeout is exceeded by then
1619 future_age_on_next_poll = future_age + (at - datetime_to_timestamp(now))
1620 if self.config.polling_timeout is not None and future_age_on_next_poll > self.config.polling_timeout:
1621 logger.debug("Polling timeout exceeded before next poll: %.2f sec > %.2f sec, aborting polling!",
1622 future_age_on_next_poll, self.config.polling_timeout)
1623 raise PollingTimeout
1624
1625 self._poll_queue.put((at, future))
1626
1627 def _poll_using_long_polling(self, future: Future) -> None:
1628 # we use problem submit time to prioritize polling of jobs submitted earlier

Callers 1

_pollMethod · 0.95

Calls 3

utcnowFunction · 0.90
datetime_to_timestampFunction · 0.90
putMethod · 0.45

Tested by

no test coverage detected