Task objects

Summary of task objects

Task objects represent operations you performed using the SDK or the UI, such as importing and exporting annotations. The Task object can make your workflow synchronous, especially for longer operations.

DataUpsertTask is a subclass of Task that represents data row upsert operations.

Methods

The main method associated with a task object is wait_till_done, which waits until the task is completed by periodically querying the server to update the task attributes. This method takes two parameters:

  1. timeout_seconds: Represents the maximum time wait_till_done can block your code. The default value is five minutes, which should be increased for longer tasks.
  2. check_frequency: Defines how often your task queries the server to update the task attributes, which defaults to two seconds. This is useful to limit the amount of API calls against our server in a given time frame.
dataset = client.get_dataset("<dataset id>")

task = dataset.create_data_rows([{
  "row_data": item_url,
  "global_key": "<unique_global_key>"
}])
task.wait_till_done(timeout_seconds=5_000, check_frequency=10)

Task Results

The task result is a collection of details, typically information on the data rows associated with the task.

dataset = client.get_dataset("<dataset id>")

task = dataset.create_data_rows([{
  "row_data": item_url,
  "global_key": "<unique_global_key>"
}])
task.wait_till_done()

print(task.result) # prints the data rows associated with the create_data_rows operation

🚧

Warning

Large results (over 150,000 data rows) can take up to 10 mins to process.

Task Errors

The task errors work similarly to the task results but contain information on any associated errors.

dataset = client.get_dataset("<dataset id>")

task = dataset.create_data_rows([{
  "row_data": item_url,
  "global_key": "<unique_global_key>"
}])
task.wait_till_done()

print(task.errors) # prints the data rows associated with the create_data_rows operation

Get tasks

You can view all tasks performed in the past 30 days on the UI notifications page, or fetch a task by its ID using client.get_task_by_id().

id = "" # Your task ID string
client.get_task_by_id(id)

🚧

Export tasks not supported

Currently, you can't retrieve export tasks using this method.