<@ULVA73B9P> How can I schedule a task or subflow ...
# marvin-in-the-wild
k
@Marvin How can I schedule a task or subflow inside a flow to be executed after 24 hours but only once
m
To schedule a task or subflow inside a flow to execute after 24 hours but only once, you can use Prefect's scheduling utilities combined with some Python async constructs. Unfortunately, I couldn't fetch a perfect documentation link due to some search issues, but here's a general idea using an async function that introduces the delay. Step-by-step approach: 1. Define Your Task or Subflow: Create the task that you want to schedule.
Copy code
python
   from prefect import flow, task

   @task
   def my_task():
       print("This task runs after 24 hours.")
2. Create a Flow with Delay: Use
asyncio.sleep()
to introduce a delay of 24 hours.
Copy code
python
   import asyncio
   from datetime import timedelta
   from prefect import flow

   # Delay function
   async def delay(duration):
       await asyncio.sleep(duration)

   @flow
   async def delayed_flow():
       # Delay for 24 hours (24 * 60 * 60 seconds)
       await delay(24 * 60 * 60)
       my_task()
3. Run Your Flow: Execute the flow, it will wait 24 hours before executing the task.
Copy code
python
   if __name__ == "__main__":
       import asyncio
       asyncio.run(delayed_flow())
Although the provided functions didn't return the expected search results this approach should work effectively. For more detailed scheduling, you might need to explore Prefect's official documentation on scheduling once it becomes accessible. If you'd like to deploy this to Prefect Cloud with a specific schedule, you'd usually use the deployment API. References: 1. Async function basic example: Async example 2. Basic task example: Task example