Task¶
Module to handle a task.
-
class
qarnot.task.Task(connection, name, profile_or_pool=None, instancecount_or_range=1, shortname=None, job=None)[source]¶ Bases:
objectRepresents a Qarnot task.
Note
A
Taskmust be created withqarnot.connection.Connection.create_task()or retrieved withqarnot.connection.Connection.tasks()orqarnot.connection.Connection.retrieve_task().-
__init__(connection, name, profile_or_pool=None, instancecount_or_range=1, shortname=None, job=None)[source]¶ Create a new
Task.Parameters: - connection (
qarnot.connection.Connection) – the cluster on which to send the task - name (
str) – given name of the task - profile_or_pool (str or
Poolor None) – which profile to use with this task, or which Pool to run task, - instancecount_or_range (int or str) – number of instances or ranges on which to run task
- shortname (
str) – userfriendly task name - job (
Job) – which job to attach the task to
- connection (
-
run(output_dir=None, job_timeout=None, live_progress=False, results_progress=None)[source]¶ Submit a task, wait for the results and download them if required.
Parameters: - output_dir (str) – (optional) path to a directory that will contain the results
- job_timeout (float) – (optional) Number of seconds before the task
abort()if it is not already finished - live_progress (bool) – (optional) display a live progress
- results_progress (bool or function(float, float, str)) – (optional) can be a callback (read,total,filename) or True to display a progress bar
Raises: - qarnot.exceptions.QarnotGenericException – API general error, see message for details
- qarnot.exceptions.MaxTaskException – Task quota reached
- qarnot.exceptions.NotEnoughCreditsException – Not enough credits
- qarnot.exceptions.UnauthorizedException – invalid credentials
Note
Will ensure all added file are on the resource bucket regardless of their uploading mode.
Note
If this function is interrupted (script killed for example), but the task is submitted, the task will still be executed remotely (results will not be downloaded)
Warning
Will override output_dir content.
-
resume(output_dir, job_timeout=None, live_progress=False, results_progress=None)[source]¶ Resume waiting for this task if it is still in submitted mode. Equivalent to
wait()+download_results().Parameters: - output_dir (str) – path to a directory that will contain the results
- job_timeout (float) – Number of seconds before the task
abort()if it is not already finished - live_progress (bool) – display a live progress
- results_progress (bool or function(float, float, str)) – can be a callback (read,total,filename) or True to display a progress bar
Raises: - qarnot.exceptions.QarnotGenericException – API general error, see message for details
- qarnot.exceptions.UnauthorizedException – invalid credentials
- qarnot.exceptions.MissingTaskException – task does not exist
Note
Do nothing if the task has not been submitted.
Warning
Will override output_dir content.
-
submit()[source]¶ Submit task to the cluster if it is not already submitted.
Raises: - qarnot.exceptions.QarnotGenericException – API general error, see message for details
- qarnot.exceptions.MaxTaskException – Task quota reached
- qarnot.exceptions.NotEnoughCreditsException – Not enough credits
- qarnot.exceptions.UnauthorizedException – invalid credentials
Note
Will ensure all added files are on the resource bucket regardless of their uploading mode.
Note
To get the results, call
download_results()once the job is done.
-
abort()[source]¶ Abort this task if running.
Raises: - qarnot.exceptions.QarnotGenericException – API general error, see message for details
- qarnot.exceptions.UnauthorizedException – invalid credentials
- qarnot.exceptions.MissingTaskException – task does not exist
-
update_resources()[source]¶ Update resources for a running task.
- The typical workflow is as follows:
- Upload new files on your resource bucket,
- Call this method,
- The new files will appear on all the compute nodes in the $DOCKER_WORKDIR folder
Note: There is no way to know when the files are effectively transfered. This information is available on the compute node only. Note: The update is additive only: files deleted from the bucket will NOT be deleted from the task’s resources directory.
Raises: - qarnot.exceptions.QarnotGenericException – API general error, see message for details
- qarnot.exceptions.UnauthorizedException – invalid credentials
- qarnot.exceptions.MissingTaskException – task does not exist
-
delete(purge_resources=False, purge_results=False)[source]¶ Delete this task on the server.
Parameters: Raises: - qarnot.exceptions.QarnotGenericException – API general error, see message for details
- qarnot.exceptions.UnauthorizedException – invalid credentials
- qarnot.exceptions.MissingTaskException – task does not exist
-
update(flushcache=False)[source]¶ Update the task object from the REST Api. The flushcache parameter can be used to force the update, otherwise a cached version of the object will be served when accessing properties of the object. Some methods will flush the cache, like
submit(),abort(),wait()andinstant(). Cache behavior is configurable withauto_updateandupdate_cache_time.Raises: - qarnot.exceptions.QarnotGenericException – API general error, see message for details
- qarnot.exceptions.UnauthorizedException – invalid credentials
- qarnot.exceptions.MissingTaskException – task does not represent a valid one
-
classmethod
from_json(connection, json_task, is_summary=False)[source]¶ Create a Task object from a json task.
Parameters: - connection (qarnot.connection.Connection) – the cluster connection
- json_task (dict) – Dictionary representing the task
Returns: The created
Task.
-
commit()[source]¶ Replicate local changes on the current object instance to the REST API
Raises: - qarnot.exceptions.QarnotGenericException – API general error, see message for details
- qarnot.exceptions.UnauthorizedException – invalid credentials
Note
When updating buckets’ properties, auto update will be disabled until commit is called.
-
wait(timeout=None, live_progress=False)[source]¶ Wait for this task until it is completed.
Parameters: Return type: Returns: Is the task finished
Raises: - qarnot.exceptions.QarnotGenericException – API general error, see message for details
- qarnot.exceptions.UnauthorizedException – invalid credentials
- qarnot.exceptions.MissingTaskException – task does not represent a valid one
-
snapshot(interval)[source]¶ Start snapshooting results. If called, this task’s results will be periodically updated, instead of only being available at the end.
Snapshots will be taken every interval second from the time the task is submitted.
Parameters: interval (int) – the interval in seconds at which to take snapshots
Raises: - qarnot.exceptions.QarnotGenericException – API general error, see message for details
- qarnot.exceptions.UnauthorizedException – invalid credentials
- qarnot.exceptions.MissingTaskException – task does not represent a valid one
Note
To get the temporary results, call
download_results().
-
instant()[source]¶ Make a snapshot of the current task.
Raises: - qarnot.exceptions.QarnotGenericException – API general error, see message for details
- qarnot.exceptions.UnauthorizedException – invalid credentials
- qarnot.exceptions.MissingTaskException – task does not exist
Note
To get the temporary results, call
download_results().
-
state¶ Type: strGetter: return this task’s state State of the task.
- Value is in
- UnSubmitted
- Submitted
- PartiallyDispatched
- FullyDispatched
- PartiallyExecuting
- FullyExecuting
- UploadingResults
- DownloadingResults
- Cancelled
- Success
- Failure
Warning
this is the state of the task when the object was retrieved, call
update()for up to date value.
-
resources¶ Type: list( Bucket)Getter: Returns this task’s resources bucket Setter: Sets this task’s resources bucket Represents resource files.
-
results¶ Type: BucketGetter: Returns this task’s results bucket Setter: Sets this task’s results bucket Represents results files.
-
download_results(output_dir, progress=None)[source]¶ Download results in given output_dir.
Parameters: Raises: - qarnot.exceptions.MissingBucketException – the bucket is not on the server
- qarnot.exceptions.QarnotGenericException – API general error, see message for details
- qarnot.exceptions.UnauthorizedException – invalid credentials
Warning
Will override output_dir content.
-
stdout()[source]¶ Get the standard output of the task since the submission of the task.
Return type: Returns: The standard output.
Raises: - qarnot.exceptions.QarnotGenericException – API general error, see message for details
- qarnot.exceptions.UnauthorizedException – invalid credentials
- qarnot.exceptions.MissingTaskException – task does not exist
Note
The buffer is circular, if stdout is too big, prefer calling
fresh_stdout()regularly.
-
fresh_stdout()[source]¶ Get what has been written on the standard output since last time this function was called or since the task has been submitted.
Return type: Returns: The new output since last call.
Raises: - qarnot.exceptions.QarnotGenericException – API general error, see message for details
- qarnot.exceptions.UnauthorizedException – invalid credentials
- qarnot.exceptions.MissingTaskException – task does not exist
-
stderr()[source]¶ Get the standard error of the task since the submission of the task.
Return type: Returns: The standard error.
Raises: - qarnot.exceptions.QarnotGenericException – API general error, see message for details
- qarnot.exceptions.UnauthorizedException – invalid credentials
- qarnot.exceptions.MissingTaskException – task does not exist
Note
The buffer is circular, if stderr is too big, prefer calling
fresh_stderr()regularly.
-
fresh_stderr()[source]¶ Get what has been written on the standard error since last time this function was called or since the task has been submitted.
Return type: Returns: The new error messages since last call.
Raises: - qarnot.exceptions.QarnotGenericException – API general error, see message for details
- qarnot.exceptions.UnauthorizedException – invalid credentials
- qarnot.exceptions.MissingTaskException – task does not exist
-
uuid¶ Type: strGetter: Returns this task’s uuid The task’s uuid.
Automatically set when a task is submitted.
-
name¶ Type: strGetter: Returns this task’s name Setter: Sets this task’s name The task’s name.
Can be set until task is submitted.
-
shortname¶ Type: strGetter: Returns this task’s shortname Setter: Sets this task’s shortname The task’s shortname, must be DNS compliant and unique, if not provided, will default to
uuid.Can be set until task is submitted.
Type: :class:list(str) Getter: Returns this task’s tags Setter: Sets this task’s tags Custom tags.
-
pool¶ Type: PoolGetter: Returns this task’s pool Setter: Sets this task’s pool The pool to run the task in.
Can be set until
run()is called.Warning
This property is mutually exclusive with
profile
-
profile¶ Type: strGetter: Returns this task’s profile Setter: Sets this task’s profile The profile to run the task with.
Can be set until
run()orsubmit()is called.Warning
This property is mutually exclusive with
pool
-
instancecount¶ Type: intGetter: Returns this task’s instance count Setter: Sets this task’s instance count Number of instances needed for the task.
Can be set until
run()orsubmit()is called.Raises: AttributeError – if advanced_rangeis not None when setting this propertyWarning
This property is mutually exclusive with
advanced_range
-
running_core_count¶ Type: intGetter: Returns this task’s running core count Number of core running inside the task.
-
running_instance_count¶ Type: intGetter: Returns this task’s running instance count Number of instances running inside the task.
-
advanced_range¶ Type: strGetter: Returns this task’s advanced range Setter: Sets this task’s advanced range Advanced instances range selection.
Allows to select which instances will be computed. Should be None or match the following extended regular expression “([0-9]+|[0-9]+-[0-9]+)(,([0-9]+|[0-9]+-[0-9]+))+” eg: 1,3-8,9,12-19
Can be set until
run()is called.Raises: AttributeError – if instancecountis not 0 when setting this propertyWarning
This property is mutually exclusive with
instancecount
-
snapshot_whitelist¶ Type: strGetter: Returns this task’s snapshot whitelist Setter: Sets this task’s snapshot whitelist Snapshot white list (regex) for
snapshot()andinstant()Can be set until task is submitted.
-
snapshot_blacklist¶ Type: strGetter: Returns this task’s snapshot blacklist Setter: Sets this task’s snapshot blacklist Snapshot black list (regex) for
snapshot()instant()Can be set until task is submitted.
-
results_whitelist¶ Type: strGetter: Returns this task’s results whitelist Setter: Sets this task’s results whitelist Results whitelist (regex)
Can be set until task is submitted.
-
results_blacklist¶ Type: strGetter: Returns this task’s results blacklist Setter: Sets this task’s results blacklist Results blacklist (regex)
Can be set until task is submitted.
-
status¶ Type: qarnot.status.StatusGetter: Returns this task’s status Status of the task
-
completed_instances¶ Type: list( CompletedInstance)Getter: Return this task’s completed instances
-
creation_date¶ Type: strGetter: Returns this task’s creation date Creation date of the task (UTC Time)
-
errors¶ Type: list( Error)Getter: Returns this task’s errors if any. Error reason if any, empty string if none
-
constants¶ Type: dictionary{ str:str}Getter: Returns this task’s constants dictionary. Setter: set the task’s constants dictionary. Update the constants if needed Constants are the parametrazer of the profils. Use them to adjust your profile parametter.
-
constraints¶ Type: dictionary{ str:str}Getter: Returns this task’s constraints dictionary. Setter: set the task’s constraints dictionary. Update the constraints if needed advance usage
-
wait_for_pool_resources_synchronization¶ Type: boolor NoneGetter: Returns this task’s wait_for_pool_resources_synchronization. Setter: set the task’s wait_for_pool_resources_synchronization. Raises: qarnot.exceptions.AttributeError – can’t set this attribute on a launched task
-
auto_update¶ Type: boolGetter: Returns this task’s auto update state Setter: Sets this task’s auto update state Auto update state, default to True When auto update is disabled properties will always return cached value for the object and a call to
update()will be required to get latest values from the REST Api.
-
update_cache_time¶ Type: intGetter: Returns this task’s auto update state Setter: Sets this task’s auto update state Cache expiration time, default to 5s
-
auto_delete¶ Autodelete this Task if it is finished and your max number of task is reach
Can be set until
run()orsubmit()is called.Type: boolGetter: Returns is this task must autodelete Setter: Sets this task’s autodelete Default_value: “False” Raises: AttributeError – if you try to reset the auto_delete after the task is submit
-
completion_ttl¶ The task will be auto delete completion_ttl after it is finished
Can be set until
run()orsubmit()is called.Getter: Returns this task’s completed time to live. Type: strSetter: Sets this task’s this task’s completed time to live. Type: strordatetime.timedeltaDefault_value: “” Raises: AttributeError – if you try to set it after the task is submitted The completion_ttl must be a timedelta or a time span format string (example: ‘d.hh:mm:ss’ or ‘hh:mm:ss’)
-
-
class
qarnot.task.CompletedInstance(json)[source]¶ Bases:
objectCompleted Instance Information
Note
Read-only class
-
results= None¶ Type: :class:list(str) Instance produced results
-