Data Addition
trigger type on Latch which will run a target workflow on all children of the target directory. We assume that you understand how to write and register Workflows on Latch.
Prerequisites:
latch init test-workflow
.__init__.py
and task.py
with the following sample code.
latch register --remote --yes test-workflow
.literal
object, and pass it to params
.
Processed Directory
with the directory name of processed children.
For many common use cases, Registry serves as the location to track workflow inputs and outputs, and hence we include an example of it here. However, having a registry table is not required, if you don’t want to use Registry as a mean to track your inputs and outputs.
To create a new table to be used with the automation:
New Table
.automation-wf/wf
directory.
__init__.py
calls the automation task defined in automation.py
.automation.py
contains the Python logic to determine how a workflow should be launched.util.py
contains the utility function which launches target workflow.wf/__init__.py
and specify your name in workflow metadata:
output_directory
: The Latch Path to the output folder which this automation workflow will populate. i.e. latch://...
target_wf_id
: The ID of the target workflow that you have just created.params
: The parameters for your workflow. Refer to Create The Target Workflow to get the parameters.table_id
: The ID of the table which you created that stores metadata for this automation. Refer to Create A New Registry Table to create a table and get the ID.Important: Currently, automations are only passinginput_directory
as the parameter to the automation workflow. If your workflow has different parameters automation will fail to start it.
In case you need more parameters to pass to your automation workflow, we suggest to hard-code them into the workflow while we are working on adding parameter support for automations.
automation.py
from step 1.6 if your target workflow takes different parameters than input_directory
and output_directory
:
input_directory
refers to the child directory (i.e. the trigger directory) to be passed to the target workflow.output_directory
refers to directory where the output of the target workflow will be stored.wf/automation.py
contains the logic that determines how an execution for the target workflow should be launched.
The automation_task
defines the logic that is used to launch the workflow. The code below checks a registry table to see whether an output directory exists, and launches an execution for the target workflow if that is not the case.
Modify the function below to change the logic for launching target workflows.
Event Type
as Data Added
.
Follow-up Update Period
to something short like 30 seconds to make your automation easy to test.
Select Target
button. Any items uploaded to this folder will trigger the automation workflow.