saq.utils

Utils

Module Contents

saq.utils.now()[source]

Gets current time in milliseconds since epoch

Return type:

int

saq.utils.uuid1()[source]

Generates a string representation of a UUID1

Return type:

str

saq.utils.millis(s)[source]

Converts from seconds to milliseconds

Parameters:

s (float)

Return type:

float

saq.utils.seconds(ms)[source]

Converts from milliseconds to seconds

Parameters:

ms (float)

Return type:

float

saq.utils.exponential_backoff(attempts, base_delay, max_delay=None, jitter=True)[source]

Get the next delay for retries in exponential backoff.

Parameters:
  • attempts (int) – Number of attempts so far

  • base_delay (float) – Base delay, in seconds

  • max_delay (float | None) – Max delay, in seconds. If None (default), there is no max.

  • jitter (bool) – If True, add a random jitter to the delay

Returns:

Delay in seconds

Return type:

float

async saq.utils.cancel_tasks(tasks)[source]

Cancel tasks and wait for all of them to finish

Parameters:

tasks (collections.abc.Iterable[asyncio.Task])

Return type:

None