https://prefect.io logo
m

Martin Teller

02/15/2022, 10:37 AM
Hi ๐Ÿ™‚, I am scoring the documentation but havenโ€™t found the answer yet: on prefect-cloud (in particular) is it possible to run a flow when it receives an http request? What would this look like in prefect?
a

Anna Geller

02/15/2022, 10:43 AM
Yes, it's possible! ๐Ÿ™‚ We have a topic about event-driven workflows here https://discourse.prefect.io/t/is-there-an-equivalent-to-sensors-in-prefect-how-do-i-trigger-event-driven-workflows/76 In short, you can e.g. trigger a flow run from some external API using the GraphQL create_flow_run mutation e.g.
Copy code
import requests

query = """
 mutation {
  create_flow_run(input: { version_group_id: "fb919cc4-7f74-4ed7-9f3c-71bdd9be69e8" }) {
    id
  }
}
"""

url = "<https://api.prefect.io>"
response = <http://requests.post|requests.post>(
    url, json={"query": query}, headers={"authorization": "Bearer XXX"}
)
print(response.status_code)
print(response.text)
m

Martin Teller

02/15/2022, 12:22 PM
Thank you @Anna Geller this is exactly what I was looking for! ๐Ÿ‘
๐Ÿ‘ 1
6 Views