benchling_sdk.helpers.task_helpers module¶

class EmptyTaskResponse¶

Bases: object

A sentinel object used for tasks that do not return any response data on completion.

class TaskCompletion¶

Bases: Generic[benchling_sdk.helpers.task_helpers.ResponseT]

Return type for TaskHelper.wait_for_task, same as AsyncTask but with a typed response.

__init__(success: bool, errors: Optional[AsyncTaskErrors] = None, message: Optional[str] = None, response: Optional[benchling_sdk.helpers.task_helpers.ResponseT] = None) → None¶
errors: Optional[AsyncTaskErrors] = None¶
message: Optional[str] = None¶
response: Optional[benchling_sdk.helpers.task_helpers.ResponseT] = None¶
success: bool¶
exception TaskFailureException¶

Bases: Exception

Exception type used by TaskHelper methods.

__init__(errors: AsyncTaskErrors, message: Optional[str]) → None¶
errors: AsyncTaskErrors¶
message: Optional[str]¶
class TaskHelper¶

Bases: benchling_api_client.v2.stable.models.async_task_link.AsyncTaskLink, Generic[benchling_sdk.helpers.task_helpers.ResponseT]

Used by Benchling async task endpoints to provide the task response in an appropriate type.

In the API spec, endpoints that create a long-running task are defined as returning an benchling_sdk.models.AsyncTaskLink, which can be used with benchling_sdk.services.v2.stable.TaskService to query the task status and response. But AsyncTaskLink and the task query endpoint do not define a specific schema for the task response.

To work around that limitation, those SDK endpoints now return a TaskHelper instead. This is subclassed from AsyncTaskLink for backward compatibility, but unlike AsyncTaskLink, TaskHelper knows what the type of the task response should be. It also retains an association with the API client, so rather than calling a separate service method, you can simply call TaskHelper.wait_for_completion() or TaskHelper.wait_for_response().

You can access a task for up to 30 minutes after its completion, after which its data will no longer be available.

__init__(from_task_link: AsyncTaskLink, client: benchling_api_client.v2.client.Client, response_class: Type[benchling_sdk.helpers.task_helpers.ResponseT])¶

Initialize the instance. This should only be used internally by Benchling API methods.

wait_for_completion(interval_wait_seconds: int = 1, max_wait_seconds: int = 600) → TaskCompletion[benchling_sdk.helpers.task_helpers.ResponseT]¶

Wait for the task to succeed or fail.

This is equivalent to the benchling_sdk.services.v2.stable.task_service.TaskService.wait_for_task() method in benchling_sdk.services.v2.stable.task_service.TaskService, except that instead of returning an benchling_sdk.models.AsyncTask whose response property is a dict, it returns a TaskCompletion whose response property is the appropriate type for the API method you called. For instance, if the method was AaSequenceService.bulk_create, the response type will be benchling_sdk.models.BulkCreateAaSequencesAsyncTaskResponse.

Parameters
  • interval_wait_seconds – time to wait between API calls in seconds

  • max_wait_seconds – maximum wait time in seconds before raising an error

Returns

The task completion status. Check status for success or failure

Return type

TaskCompletion

Raises

WaitForTaskExpiredError – if the maximum wait time has elapsed

wait_for_response(interval_wait_seconds: int = 1, max_wait_seconds: int = 600) → benchling_sdk.helpers.task_helpers.ResponseT¶

Wait for the task and return the response object on success, or raise an exception on failure.

This is a convenience method for calling wait_for_completion() and then getting the response property of the returned object if the task succeeded, in cases where you’re not interested in any TaskCompletion properties except the response.

The type of the returned object is depends on the API method you called. For instance, if the method was AaSequenceService.bulk_create, the response type will be benchling_sdk.models.BulkCreateAaSequencesAsyncTaskResponse.

Parameters
  • interval_wait_seconds – time to wait between API calls in seconds

  • max_wait_seconds – maximum wait time in seconds before raising an error

Returns

The response object, if the task succeeded.

Return type

ResponseT

Raises
  • WaitForTaskExpiredError – if the maximum wait time has elapsed

  • .TaskFailureException – if the task failed