<@ULVA73B9P> syntax for running a flow by event of...
# ask-marvin
r
@Marvin syntax for running a flow by event of completion of another flow
m
thought for 42.5 seconds
Based on the research, in Prefect 3.x, you can trigger a flow based on another flow's completion using Automations. Here's how it works: 1. Via the Prefect UI: - Navigate to the Automations page - Create a new automation - Select "Flow run state change" as the trigger - Configure the conditions (e.g., specific flow name and "Completed" state) - Select the flow you want to trigger as the action 2. Programmatically using the API:
Copy code
python
from prefect.client.orchestration import get_client
from prefect.client import PrefectClient
from prefect.events import Event

async def create_automation():
    async with get_client() as client:
        await client.create_automation(
            name="Trigger Flow B on Flow A completion",
            trigger={"type": "flow_run_state_change", 
                    "flow_name": "Flow A",
                    "state_names": ["Completed"]},
            actions=[{
                "type": "run_deployment",
                "deployment_name": "your-deployment-name/tag"
            }]
        )
Key points to remember: - Automations provide a flexible way to create event-driven workflows - You can trigger flows based on various states (Completed, Failed, etc.) - Flows remain independent and can run on different infrastructure - You can set up multiple triggers and conditions for sophisticated automation patterns For more detailed information, you can check out: - The Automations documentation: https://docs-3.prefect.io/v3/concepts/automations - Workflow design patterns: https://www.prefect.io/blog/workflow-design-patterns Would you like me to provide more specific examples for your use case or explain any part of this in more detail?
r
@Marvin is there any difference between code execution using quick run and cron scheduled run
m
thought for 52.9 seconds
Let me break down the key differences and similarities between quick runs and cron-scheduled runs: ### Similarities 1. Code Execution: - The actual code execution remains identical - Both use the same deployment configuration and infrastructure - Environment variables and dependencies are handled the same way - Flow logic and task execution patterns remain consistent 2. Environment: - Both types of runs use the same environment configuration - Infrastructure settings (like Docker containers or Kubernetes pods) remain consistent - Access to resources and dependencies is identical ### Key Differences 1. Initiation Method: - Quick Runs: Manually triggered, immediate execution - Cron Runs: Automatically triggered based on schedule 2. Scheduling Behavior: - Quick Runs: One-off executions without future planning - Cron Runs: Predictable, recurring executions with up to 100 days of future runs created 3. Use Cases: - Quick Runs: - Testing and debugging - Ad-hoc analysis - Immediate response to events - Development and validation - Cron Runs: - Regular data processing - Scheduled reporting - Automated maintenance tasks - Periodic data synchronization 4. Operational Aspects: - Quick Runs: Require manual intervention, better for development - Cron Runs: Automated, better for production workloads ### Important Notes - The actual flow execution remains identical - the differences are primarily in how and when the flow is triggered - Both types can be monitored and tracked in the same way through the Prefect UI - Both support the same logging and observability features - You can use the same flow code for both quick runs and scheduled runs For more detailed information about schedules in Prefect, you can refer to the documentation at: https://docs-3.prefect.io/v3/concepts/schedules Would you like me to elaborate on any specific aspect of these differences or provide examples of how to set up either type of run?