HTC Tasks
This module has functions that help with Rescale Tasks. Tasks are returned as a HtcTask object, which can be used for later library calls.
- class rescalehtc.htctasks.HtcTask(json: dict, project: HtcProject)
Class which represents a single Rescale Task. Use the functions in rescalehtc.tasks to create this object.
- json
The raw dictionary describing this Task. The dictionary follows the HTCTask schema in the Rescale HTC API documentation. Example contents:
{ "projectId": "project-12345", "taskId": "task-12345", "taskName": "my-task", "taskDescription": "my sample task", "createdBy": "qWoUF", "createdAt": "2023-10-19T10:00:55.370Z", "workspaceId": "04-8473942", "taskFolderPath": "projects/project-12345/tasks/task-12345", "lifecycleStatus": "ACTIVE" }
Access this member variable to extract information about a task.
- get_task_summary(rescale: HtcSession) dict
Returns the task summary for this HtcJobBatch’s task. This contains summary of how many jobs are running, succeeded, failed etc within this task. Example return value:
{ "group": null, "jobStatuses": { "SUBMITTED_TO_RESCALE": 1, "SUBMITTED_TO_PROVIDER": 0, "RUNNABLE": 0, "STARTING": 0, "RUNNING": 0, "SUCCEEDED": 0, "FAILED": 0 }, "still_running": true }
Adds a field called “still_running” to the return dict, which is true if any container is in any state not equal to SUCCEEDED or FAILED.
This function has basic flood prevention on the job status requests. The API never updates more than every 30 seconds anyway, so calling this function more often than that has no effect.
- is_still_running(rescale: HtcSession) bool
Returns false if all jobs within this task are in the SUCCEEDED or FAILED states, otherwise return true as one or more jobs are still running/pending. Equivalent to the “still_running” field in
rescalehtc.htctasks.HtcTask.get_task_summary().Use this function in a loop with 30 second intervals to wait for job completion.
while task.is_still_running(): time.sleep(30) print("Completed all jobs in task") print(task.get_task_summary())
This function has basic flood prevention on the job status requests. The API never updates more than every 30 seconds anyway, so calling this function more often than that has no effect.
- delete_task(rescale: HtcSession)
Delete this task.
- cancel_jobs_in_task(rescale: HtcSession)
Cancels all the jobs within this task. Tasks that have not yet started will not start, and running tasks will be stopped.
- rescalehtc.htctasks.get_tasks_with_name(rescale: HtcSession, project: HtcProject, task_name: str, lifecycle_status: str = 'ACTIVE') list[HtcTask]
Get a list of tasks that match a certain name, within a given project and matching a given lifecycle_status. To find tasks in any lifecycle_status task, set lifecycle_status to
any. Returns a list of HtcTask objects.
- rescalehtc.htctasks.get_task_with_id(rescale: HtcSession, project: HtcProject, task_id: str) HtcTask
Get a task with a certain taskId, within a given project.
If the taskId is not found, returns None.
- rescalehtc.htctasks.get_tasks(rescale: HtcSession, project: HtcProject, lifecycle_status: str = 'ACTIVE') list[HtcTask]
Get all tasks within a given project that matches a given lifecycle_status. To find tasks in any lifecycle_status task, set lifecycle_status to
any. Returns a list of HtcTask objects.
- rescalehtc.htctasks.create_task_with_name(rescale: HtcSession, project: HtcProject, task_name, task_description='') HtcTask
Create a Rescale task with a specific task name, and an optional task description.
Returns a HtcTask object.
- rescalehtc.htctasks.delete_tasks_with_name(rescale: HtcSession, project: HtcProject, task_name: str) list[dict]
Delete all tasks that match a specific task name. This may delete multiple tasks. Returns a list of json descriptions of the tasks that were deleted, or an empty list if no tasks where affected.
- rescalehtc.htctasks.delete_task_with_id(rescale: HtcSession, project: HtcProject, task_id: str) dict
Delete a task matching a given ID within the provided project. The json describing the deleted task is returned.
None is returned if the taskId does not exist.