For conceptual breakdown of the diagram, go to Architecture Diagrams Walkthrough.
1. Create a work pool or choose one that already exists in your workspace.
Creating a work pool in the UI is recommended for your first go of it so you that get a sense of all the options.
-
Select
Docker
for the work pool type. -
Call your work pool something like
name-pacc-work-pool
. -
Check out the infrastructure configuration options, but feel free to leave them empty (default) for now.
-
Verify this worked by running the following in your terminal:
To see any existing work pools:
prefect work-pool ls
-
Alternatively, you can create a work pool with the following command:
prefect work-pool create "my-pacc-work-pool" --type docker
2. Start a worker to poll this work pool.
-
Ensure the Docker daemon is running on your laptop.
-
Install the required library:
pip install prefect-docker
-
On your laptop, open up a new terminal, activate your Python environment, and type:
prefect worker start --pool my-pacc-work-pool
-
Keep this terminal process running for as long as you want to run deployments on your laptop.
3. Create a deployment to send your flow to your work pool.
-
Again, ensure the Docker daemon is running because, when you run
flow.deploy()
, Prefect will build a custom Docker image containing your workflow code that the worker can use to dynamically spawn Docker containers whenever this workflow needs to run. -
Use the
flow.deploy()
method to define a deployment:Check out the schedule options here. Choose between
cron
,interval
, orrrule
. In the example below we set an interval schedule for every 50 minutes.my_flow.py
from prefect import flow @flow(log_prints=True) def my_flow(name: str = "World"): print(f"Hello {name}!") if __name__ == "__main__": my_flow.deploy( name="taylor-pacc-deployment", # add your name and 'pacc' work_pool_name="my-pacc-work-pool", # work pool you created earlier image="my-first-deployment-image:pacc", # name this whatever you like push=False, tags=["pacc", "taylor"], # add tags interval=3000 # schedule )
-
Run your python script:
python my_flow.py
-
Alternatively, you can run the deployment from the CLI
prefect deployment run 'my_flow/my-deployment'
- Add an infrastructure-level override such as an environment variable by specifying a
job_variable
on your deployment. - Go to the Advanced tab of your work pool's setting to customize your work pool's job configuration.
- Pause, cancel, and/or retry your flow run.