Scenario submission
This section provides details on how to submit a Scenario
, a Sequence
, or
a Task
for execution.
Main principle¶
Submitting a Scenario
, a Sequence
, or a Task
, is the same as submitting
a set of tasks for execution. Each task execution is represented by a Job
entity that is created when the task is submitted. The Job
entity holds the
status of the task execution and other related information.
To submit an entity, you need to call the taipy.submit()
function. This function
creates the Job
entities and returns a Submission
object as an entity holding
the jobs, the submission status, and other related information.
Submit a scenario¶
In a Taipy application, running the Orchestrator service is required to execute jobs. To see how you can run different Taipy services, please refer to the running Taipy services page.
Preventing configuration update when the Orchestrator service is running
After running the Orchestrator service, all configuration are blocked from update.
In this section, it is assumed that
my_config.py
module contains a Taipy configuration already implemented. For more details on how to
configure a scenario for Task execution, see the
scenario configuration page.
To execute a scenario, you need to call the taipy.submit()
function. It returns a
Submission
object containing the information about the submission of the scenario
such as the created Job
s representing a Task
in the submitted scenario:
1 2 3 4 5 6 7 8 |
|
In line 7, we create a new scenario from a scenario configuration and submit it for
execution (line 8). The taipy.submit()
method triggers the submission of all the
scenario's tasks.
The Orchestrator service can also be started after taipy.submit()
method. Note that
jobs can only be executed after the Taipy Orchestrator service is started:
1 2 3 4 5 6 7 8 9 |
|
Another syntax.
To submit a scenario, you can also use the method Scenario.submit()
:
1 2 3 4 5 6 7 8 |
|
By default, Taipy will asynchronously execute the jobs. If you want to wait until the submitted jobs are finished, you can use the parameter wait and timeout:
1 2 3 4 5 6 7 8 9 10 |
|
Submit a sequence¶
It is also possible to submit a Sequence
using the same taipy.submit()
function. It
returns a Submission
object containing the information about the submission of the sequence
such as the created Job
s representing the Task
s in the submitted sequence:
1 2 3 4 5 6 7 8 9 10 |
|
In line 8, we retrieve the sequence named sales_sequence
from the created scenario. In line 10,
we submit this sequence for execution. The taipy.submit()
method triggers the submission of all
the sequence's tasks. When submitting a sequence, you can also use the two parameters wait and
timeout.
Another syntax.
To submit a sequence, you can also use the method Sequence.submit()
:
1 2 3 4 5 6 7 8 9 |
|
Submit a task¶
You can also submit a single task with the same taipy.submit()
function. It returns a
Submission
object containing the information about the submission of the task such as
the created Job
representing the submitted Task
:
1 2 3 4 5 6 7 8 9 10 |
|
In line 8, we retrieve the task named predicting
from the created scenario. In line 10, we submit this
task for execution. When submitting a task, you can also use the two parameters wait and timeout.
Another syntax.
To submit a task, you can also use the method Task.submit()
:
1 2 3 4 5 6 7 8 9 |
|
Subscribe to job execution¶
You can subscribe to a Sequence
or a Scenario
execution to be notified when a job
status changes.
If you want a function named my_function()
to be called on each status change of each
task execution of all scenarios, use taipy.subscribe_scenario(my_function)
. You can use
taipy.subscribe_sequence(my_function)
to work at the sequence level.
If you want your function my_function()
to be called for each task of a scenario called
my_scenario
, you should call taipy.subscribe_scenario(my_function, my_scenario)
. It is
similar in the context of sequences: to be notified on a given sequence stored in my_sequence
,
you must call taipy.subscribe_sequence(my_function, my_sequence)
.
You can also define a function that receives multiple parameters to be used as a subscriber.
It is similar to the example above, you can just add your parameters as a list, for example
taipy.subscribe_scenario(my_function, ["my_param", 42], my_scenario)
.
You can also unsubscribe to scenarios by using taipy.unsubscribe_scenario(function)
or tp.unsubscribe_sequence(function)
for sequences. Same as for subscription, the un-subscription
can be global, or you can specify the scenario or sequence by passing it as a parameter.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
|
This example will produce the following output:
Submit: scenario_1
my_global_subscriber: scenario 'my_scenario_1'; task 'my_task_1'.
my_subscriber: scenario 'my_scenario_1'; task 'my_task_1'.
my_subscriber_multi_param: params ["my_param_1", 42]; task 'my_task_1'.
my_subscriber: scenario 'my_scenario_1' ; task 'my_task_2'.
my_subscriber_multi_param: params ["my_param_1", 42]; task 'my_task_2'.
Submit: scenario_2
my_global_subscriber: scenario 'my_scenario_2'; task 'my_task_1'.
Unsubscribe to my_global_subscriber for scenario_1
Submit: scenario_1
my_subscriber: scenario 'my_scenario_1'; task 'my_task_1'.
my_subscriber_multi_param: params ["my_param_1", 42]; task 'my_task_1'.
my_subscriber: scenario 'my_scenario_1'; task 'my_task_2'.
my_subscriber_multi_param: params ["my_param_1", 42]; task 'my_task_2'.