Skip to content

Task management

Tasks get created when scenarios are created. Please refer to the Entities' creation section for more details.

In this section, it is assumed that my_config.py module contains a Taipy configuration already implemented.

Task attributes

Now that we know how to create a new Task, this section focuses on describing the task's attributes and utility methods.

A Task entity is identified by a unique identifier id Taipy generates. A task also holds various properties accessible as an attribute of the task:

  • config_id is the id of the scenario configuration.
  • input is the list of input data nodes.
  • output is the list of output data nodes.
  • function is the Python function associated with the Task config.
    The function takes as many parameters as there are data nodes in the input attribute. Each parameter corresponds to the return value of an input data node read() method.
    The function returns as many parameters as there are data nodes in the output attribute. Each function's returned value corresponds to the parameter of an output data node write() method.
  • version: The string indicates the application version of the task to instantiate. If not provided, the current version is used. Refer to the version management page for more details.
  • skippable: Boolean attribute indicating if a task execution can be skipped when all output data nodes are up-to-date (see the validity_period attribute in the Data node management page for more detail). The default value of skippable is False.

Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
import taipy as tp
import my_config

scenario = tp.create_scenario(my_config.monthly_scenario_cfg)
task = scenario.predicting

# the config_id is an attribute of the task. Here it equals "predicting"
task.config_id

# the function to be executed with data from input data
# nodes and returns value for output data nodes.
task.function # predict

# input is the list of input data nodes of the task
task.input # [trained_model_cfg, current_month_cfg]

# output is the list of output data nodes of the task
task.output # [sales_predictions_cfg]

# the current_month data node entity is exposed as an attribute of the task
current_month_data_node = task.current_month

Taipy exposes multiple methods to manage the various tasks.

Get Tasks

The first method to access a job is from its id by using the taipy.get() method.

1
2
3
4
5
6
7
import taipy as tp
import my_config

scenario = tp.create_scenario(my_config.monthly_scenario_cfg)
task = scenario.training
task_retrieved = tp.get(task.id)
# task == task_retrieved

Here, the two variables task and task_retrieved are equal.

All the jobs can be retrieved using the method taipy.get_tasks().

Get tasks by config id

A task can be retrieved from a scenario or a sequence, by accessing the task config_id attribute.

1
2
3
4
task_1 = scenario.predicting  # "predicting" is the config_id of the predicting Task in the scenario
sequence = scenario.sales
task_2 = sequence.predicting  # "predicting" is the config_id of the predicting Task in the sequence
# task_1 == task_2

Tasks can also be retrieved using taipy.get_entities_by_config_id() providing the config_id. This method returns the list of all existing tasks instantiated from the config_id provided as a parameter.

Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
import taipy as tp
import my_config

# Create 2 scenarios, which will also create 2 trainig tasks.
scenario_1 = tp.create_scenario(my_config.monthly_scenario_cfg)
scenario_2 = tp.create_scenario(my_config.monthly_scenario_cfg)

# Get all training tasks by config id, this will return a list of 2 training tasks
# created alongside the 2 scenarios.
all_training_tasks = tp.get_entities_by_config_id("training")

Get parent scenarios and sequences

To access the parent entities of a task (scenarios or sequences), you can use either the method Task.get_parents() or the function taipy.get_parents(). Both return the parents of the task.

Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
import taipy as tp
import my_config

# Create a scenario from a config
scenario = tp.create_scenario(my_config.monthly_scenario_cfg)

# Retrieve a task
task = scenario.training_cfg

# Retrieve the parent entities of the task. The returned value is
# {'scenarios': [Scenario 1], 'sequences': [Sequence 1]}
parent_entities = task.get_parents()

# Retrieve the parent entities of the task. The return value is
# {'scenarios': [Scenario 1], 'sequences': [Sequence 1]}
tp.get_parents(task)

The next section shows the data node management.