-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
524 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Adding a Database Trigger to a Lattice\n", | ||
"\n", | ||
"This example illustrates how to use a covalent.trigger.DatabaseTrigger to trigger workflow dispatches automatically at a specified interval.\n", | ||
"\n", | ||
"## Prerequisites\n", | ||
"\n", | ||
"Import Covalent and the trigger." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 10, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import covalent as ct\n", | ||
"from covalent.triggers import DatabaseTrigger" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Procedure\n", | ||
"\n", | ||
"1. Create a `Database Trigger` object that performs a trigger." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 12, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"database_trigger = DatabaseTrigger(db_path='path/to/your/database',table_name='table name')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"2. Create a workflow:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 13, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"@ct.lattice\n", | ||
"@ct.electron\n", | ||
"def my_workflow():\n", | ||
" return 42" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"3. Dispatch `my_workflow`, disabling its first execution using the `disable_run` parameter in `ct.dispatch`." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 14, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"5041f1fc-8943-4b96-9f26-a3c7f35cabef\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"dispatch_id = ct.dispatch(my_workflow)()\n", | ||
"print(dispatch_id)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"4. Attach the trigger to the `dispatch_id` and register it with the trigger server." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 15, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"database_trigger.lattice_dispatch_id = dispatch_id\n", | ||
"database_trigger.register()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"5. Monitor the Covalent UI. Watch the Dashboard for new dispatches of `my_workflow`.\n", | ||
"\n", | ||
"6. In the Covalent UI, observe that a new `my_workflow` is dispatched every five seconds.\n", | ||
"\n", | ||
"7. To disable triggers on the dispatch, use the `ct.stop_triggers` function." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 16, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"[2023-09-22 07:37:27,218] [DEBUG] local.py: Line 334 in stop_triggers: Triggers for following dispatch_ids have stopped observing:\n", | ||
"[2023-09-22 07:37:27,220] [DEBUG] local.py: Line 336 in stop_triggers: 5041f1fc-8943-4b96-9f26-a3c7f35cabef\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"ct.stop_triggers(dispatch_id)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Note that the `stop_triggers` function disables all triggers attached to the specified dispatch. \n", | ||
"\n", | ||
"## See Also\n", | ||
"\n", | ||
"[Adding a Directory Trigger to a Lattice](./trigger_dir.ipynb)\n", | ||
"\n", | ||
"[Adding a TimeTrigger to a Lattice](./trigger_time.ipynb)\n", | ||
"\n", | ||
"[Adding a SQLite Trigger to a Lattice](./trigger_sqlite.ipynb)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"###### " | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.8.17" | ||
}, | ||
"vscode": { | ||
"interpreter": { | ||
"hash": "ffe78875ce1aa6161f50f6a6dec2555e7255bbdb44cc39b93c0dfc1daa8da522" | ||
} | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.