Skip to content

Occasional rate limit issue with Tasks API #54

@davidlang42

Description

@davidlang42

Need to use backoff code for all "Tasks" calls:

const BACKOFF_WAIT_START = 1; // ms
const DEFAULT_MAX_TOTAL_WAIT = 1000; // ms

function runWithBackoff(func, max_total_wait) {
  max_total_wait = max_total_wait ?? DEFAULT_MAX_TOTAL_WAIT;
  let ms = BACKOFF_WAIT_START;
  let total = 0;
  while (true) {
    try {
      return func();
    } catch(err) {
      if (total < max_total_wait) {
        Utilities.sleep(ms);
        total += ms;
        ms = ms * 2;
      } else {
        throw new Error("After waiting " + total + "ms: " + err.message);
      }
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions