This repository contains an example of how to integrate Temporal and Modal using Sandboxes. We create a Modal App that launches Temporal Workers. These workers serve as the compute layer for running Temporal Workloads.
Rename .env.example to .env. Then populate .env.example with required
environment variableS:
TEMPORAL_SERVER_URL=
TEMPORAL_API_KEY=
TEMPORAL_NAMESPACE=Then make them available in your environment with:
export $(cat .env)Now create a Modal Secret called temporal-secrets with those three
environment variable.
Create Volume and sync workflow, activity, and config files with:
python sync_files.pyThis will store files from the following directories into a Modal Volume:
/workflows: defines Temporal Workflows/activities: defines Temporal Activities (aka functions)/configs: groups Workflows and Activities in a config
Configs are designed to configure workers to start only with a set of workflows.
The Modal App contains (A) a function to build images using conda to manage
environments and (B) a scheduled Modal Function that builds images automatically
(this is designed to observe a database and build images that match a conda
environment).
modal deploy deploy.pyRun the example script with:
python run_example.pyThis will
- Build an image, using
condato install dependencies - Start a Temporal Worker with the image ID above
- Trigger a Temporal Workflow, which runs in the Worker above