Spawning Child Jobs#
Using Orchestration Python, you can have a running job create one or more sub-jobs. This is commonly useful if your main workflow needs to initiate another workflow or set of workflows.
E.g. - A plate_loading_workflow spawns several plate_tracker_workflow child jobs to track the individual plates that were loaded - A run_tests_workflow spawns several ``
Create Child Job#
The workflow can create a sub job in the request queue of a lab using
create_child_job()
Spawn Child Job#
The workflow can a sub job and schedule it to run ASAP using
spawn_child_job()
Spawn Children Example Code#
parent_job_wf.py
from artificial.workflows.decorators import workflow
from artificial.workflows.util import create_child_job, spawn_child_job
# Import the child workflow
from child_job_wf import child_job
@workflow('Job Spawning', 'wf_parent', 'lab_c9eae09e-ceed-46d1-8390-87ff7dd8586d')
async def parent() -> None:
num_samples = 1
# This job will spawn and go into the request queue
# The function name and params match the child workflows function definition in the child workflow
await create_child_job(
child=child_job(plate_barcode='Test_1', num_samples=num_samples),
job_name='Job 1'
)
num_samples += 1
# This job will spawn and be immediately scheduled
# The function name and params match the child workflows function definition in the child workflow
await spawn_child_job(
child=child_job(plate_barcode='Test_2', num_samples=num_samples),
job_name='Running Job 1'
)
child_job_wf.py
from artificial.workflows.decorators import workflow
from artificial.workflows.runtime import show_info
@workflow('Child Job', 'wf_child', 'lab_c9eae09e-ceed-46d1-8390-87ff7dd8586d')
@parameter('plate_barcode', {'uiTitle': 'Plate Barcode'})
@parameter('num_samples', {'uiTitle': 'Number of Samples'})
# This is the function name and definition being passed into create/spawn child
async def child_job(plate_barcode: str, num_samples: int) -> None:
await show_info(f'Barcode: {plate_barcode}, num_samples: {num_samples}')