Kesavan Madheswaran
07/05/2024, 12:17 PMMarvin
07/05/2024, 12:17 PMpython
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.
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.
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