Hi All... import os from datetime import timedelt...
# ask-community
g
Hi All... import os from datetime import timedelta from prefect import flow, task from prefect.server.schemas.schedules import IntervalSchedule from prefect.deployments import Deployment @task def hello(server): print('hello', server @flow() def transformation_one(): hello('one') @flow() def transformation_two(): hello('two') @flow() def transformation_three(): hello('three') transformation_one_deployment = Deployment.build_from_flow( flow=transformation_one, name="reporting_server-flow_one", schedule=IntervalSchedule(interval=timedelta(seconds=30)) ) transformation_two_deployment = Deployment.build_from_flow( flow=transformation_two, name="reporting_server-flow_two", schedule=IntervalSchedule(interval=timedelta(seconds=30)), ) transformation_three_deployment = Deployment.build_from_flow( flow=transformation_three, name="reporting_server-flow_three", schedule=IntervalSchedule(interval=timedelta(seconds=30)) ) if name == "__main__": transformation_one_deployment.apply() transformation_two_deployment.apply() transformation_three_deployment.apply() os.system('prefect agent start -q default') I have a script similar, this is saved in a file named scheduler.py.....When I'm trying to run , I see only this , none of my flows are getting triggered.......I checked by calling the flows without deployment , at that time they were working.....when used with Deployment....the flows are not running..........Can someone please help
1
j
Hey! It looks like you're running against the ephemeral api. Can you try spinning up the prefect server?
Copy code
$ prefect server start
The prefect scheduler runs as part of that server, which creates flow runs from deployments
g
Hi Jake....I tried that still I see the same result......Can you please say if there is any other way to run a flow , with out using CLI, by completely using python code
j
Are you trying to run flows on a schedule from a Deployment? Or just directly?
If you don't want to have to worry about running the prefect server, cloud might be a good option https://docs.prefect.io/2.10.12/cloud/ to check out
g
I'm trying it using Deployment
j
If you run your code:
Copy code
import os
from datetime import timedelta
from prefect import flow, task
from prefect.server.schemas.schedules import IntervalSchedule
from prefect.deployments import Deployment
@task
def hello(server):
	print('hello', server)

@flow
def transformation_one():
	hello('one')

@flow
def transformation_two():
    hello('two')

@flow
def transformation_three():
    hello('three')

transformation_one_deployment = Deployment.build_from_flow(
    flow=transformation_one,
    name="reporting_server-flow_one",
    schedule=IntervalSchedule(interval=timedelta(seconds=30))
)
transformation_two_deployment = Deployment.build_from_flow(
    flow=transformation_two,
    name="reporting_server-flow_two",
    schedule=IntervalSchedule(interval=timedelta(seconds=30)),
)
transformation_three_deployment = Deployment.build_from_flow(
    flow=transformation_three,
    name="reporting_server-flow_three",
    schedule=IntervalSchedule(interval=timedelta(seconds=30))
)

if __name__ == "__main__":
    transformation_one_deployment.apply()
    transformation_two_deployment.apply()
    transformation_three_deployment.apply()
you should see 3 deployments created
After running
prefect server start
in another process, the scheduler will generate scheduled flow runs for your deployments
To use scheduled runs from
Deployments
you'll need either the prefect server running to run the scheduler OR use a prefect cloud workspace (cloud has it's own scheduler etc.)
Then once you have scheduled runs you can run
prefect agent start
to pick up those runs
🙌 1
g
Okay........Thank you Jake