A simple single-instance implementation of ResumableTaskStore that works in both browsers and node.js. Leverages LevelDB under the hood.

Implements

Constructors

Properties

db: LevelWrapper<string>

Methods

  • Deletes the task associated with the task ID provided. No-op if the task is not found, as this implies that the task has already been completed. Called when the task has been successfully completed.

    Parameters

    • taskId: string

    Returns Promise<void>

  • Extends the timeout of the task associated with the task ID provided. No-op if the task is not found, as this implies that the task has already been completed. This allows the client that is executing the task to continue working on it before the task is considered timed out.

    Parameters

    • taskId: string

      ID of the task to extend the timeout for.

    • timeoutInSeconds: number

      Timeout in seconds from the current time.

    Returns Promise<void>

  • Grabs a number of unhandled tasks from the store. Unhandled tasks are tasks that are not currently in-flight/under processing (ie. tasks that have timed-out). NOTE: The implementation must make sure that once a task is grabbed by a client, tis timeout must be updated so that it is considered in-flight/under processing and cannot be grabbed by another client until it is timed-out.

    Parameters

    • count: number

      Desired number of tasks to grab.

    Returns Promise<ManagedResumableTask[]>

    A list of tasks exclusive for the caller to handle; or empty array if there is no tasks, or if all tasks are already grabbed by others.

  • Registers a new resumable task that is currently in-flight/under processing to the store. If the task is timed out, a client will be able to grab it through the grab() method and resume the task.

    Parameters

    • task: any

      Task specific data. This is deliberately of type any because this store should not have to be ware of its type.

    • timeoutInSeconds: number

      Timeout in seconds from the current time.

    Returns Promise<ManagedResumableTask>

    A ManagedResumableTask object that can be used to extend or delete the task.

    with code set to ResumableTaskAlreadyExists if the same task is already registered.