Manage Tasks

Manage Tasks#

An important step in the user’s workflow is monitoring/managing tasks. Whether the user is simply trying to follow the progress of a simulation, retrieve results, or even kill a task, the Task class provides the necessary tools to do so. In this section, we will cover the following topics:

  • Task monitoring: Learn how to monitor a task, such as getting its status and getting information about the outputs;

  • Killing tasks: Learn how to kill a task that hasn’t been completed yet;

Task monitoring#

The Task class provides mechanisms to track and manage the status of a task. With a Task object at hand, the user can:

  • Get the status, i.e., whether the task is started, succeeded, failed, etc (for more details, see section about task lifecycle on our tutorial);

  • Get the machine type where it ran/is running;

  • Get the execution time.

The following snippets show how to use the Task class to manage a task.

# create a new task or retrieve a task from a previous session
# task =
#   or 
# task = Task("i4ir3kvv62odsfrhko4y8w2an")

# Get status of the task.
>>> task.get_status()
<DynamicSchema: 'success'>

# Get the computational resource type where the task is
# running or was submitted to
>>> task.get_machine_type()

>>> task.get_computation_time()

# Get information about the output files generated by the simulation
>>> output_files_info = task.get_output_files_info()
>>> print(output_files_info)
Archive size: 262.00 KB
  Size         Compressed   Name
  3.12 KB      859 B        stdout.txt
  242 B        160 B        stderr.txt
  5.76 KB      4.10 KB      vtk/ParticleData_Fluid_40.vtk
  5.76 KB      4.09 KB      vtk/ParticleData_Fluid_32.vtk
  5.76 KB      4.09 KB      vtk/ParticleData_Fluid_17.vtk
  4.98 KB      989 B        log/SPH_log.txt

Other than just retrieving information about the task, the user has the option to control

Killing tasks#

Sometimes, a user finds out that there is a reason to not allow a task to reach a final state. Whether there is a mistake in the simulation input files, a running simulation has gone rogue, or simply because there is no other reason to allow a task to proceed, the user can kill a task. The Task class provides a method to kill a task that hasn’t been completed yet. Tasks in the PENDING INPUT, SUBMITTED and STARTED states can be killed (see the section on task lifecycle).

To kill a task programmatically, one has 2 options at hand: by declarative calling the kill method or interrupting the python session/script when a task is being waited in the context of a sync_context call:

# grab a task object and
# declaratively emit a kill command
>>> task = Task("i4ir3kvv62odsfrhko4y8w2an")
>>> task.kill()

# or interrupt the session while waiting for the task to complete
>>> with tak.sync_context():
        task.wait()  # <-- The remote simulation WILL DIE if the local session is
                     #     interrupted while waiting for the wait() call to return
                     #     (Ex. the user presses Ctrl+C)

Alternatively, the user can resort to the command line interface to kill the task:

$ inductiva tasks kill i4ir3kvv62odsfrhko4y8w2an
You are about to kill the following tasks:
  - i4ir3kvv62odsfrhko4y8w2an
Are you sure you want to proceed (y/[N])? y
Successfully sent kill request for task i4ir3kvv62odsfrhko4y8w2an.