https://prefect.io logo
m

mithalee mohapatra

12/22/2020, 7:31 AM
I have a question related to the Schedules and Prefect UI Scheduler. Can I use the Prefect Schedule to schedule a task in the prefect UI: I want to schedule the below code in the Prefect UI. from prefect import task, Flow from datetime import timedelta #from prefect.schedules import IntervalSchedule from prefect.schedules import Schedule from prefect.schedules.clocks import IntervalClock import pendulum from prefect.engine.executors import LocalDaskExecutor from prefect.engine.executors import DaskExecutor import prefect import boto3 @task def say_hello(): print("Hello, world!") logger = prefect.context.get("logger") logger.info("Hello, world!") try: s3 = boto3.resource('s3') except Exception as e: raise signals.FAIL(e) if name == '__main__': schedule = Schedule(clocks=[IntervalClock(start_date=pendulum.datetime(2020, 12, 21,hour=6,minute=3,second=0),interval=timedelta(minutes=2))]) with Flow("Hello") as flow: say_hello() executor=LocalDaskExecutor(scheduler="processes", num_workers=6) flow.run(executor=executor) flow.register(project_name="Hello, World!")
j

Jim Crist-Harif

12/22/2020, 3:57 PM
I'm not sure I understand the question. Yes, you should be able to schedule flows in the Prefect UI using the above schedule. You can pass the
schedule
to the
Flow
constructor to do so. See https://docs.prefect.io/core/concepts/schedules.html for more info.
m

mithalee mohapatra

12/22/2020, 6:31 PM
I can schedule my flow from Prefect UI using the schedule in UI.
My question is can I schedule my flow to run using the Prefect schedule..
with Flow("Hello",schedule) as flow: say_hello() executor=LocalDaskExecutor(scheduler="processes", num_workers=6) flow.run(executor=executor) flow.register(project_name="Hello, World!")
j

Jim Crist-Harif

12/22/2020, 6:33 PM
yes, if you set the schedule on the flow before calling
flow.register
. You can do this by passing the
schedule
to the
Flow
constructor.
m

mithalee mohapatra

12/22/2020, 6:48 PM
Ok thank you Jim. So you mean by passing the schedule in Flow constructor like: With Flow("Hello",schedule) as flow: I can schedule flow without turning on schedule on the prefect UI?
j

Jim Crist-Harif

12/22/2020, 6:49 PM
Yes, that should work.
m

mithalee mohapatra

12/22/2020, 6:50 PM
ok..let me try