https://prefect.io logo
Title
m

Mark McDonald

05/20/2020, 5:20 PM
Is there a way to add all states to a cloud hook via the graphql api? Right now, I'm having to provide a list of all possible states and would like to not have to maintain this if states get introduced/deprecated in the future. so instead of this
create_cloud_hook = f"""
mutation {{
  create_cloud_hook(input: {{
    type: WEBHOOK,
    name: "{cloud_hook_name}",
    version_group_id: "{version_group_id}",
    states: ["Cached", "Cancelled", "Failed", "Finished", "Looped", "Mapped", "Paused", "Pending", "Queued", "Resume", "Retrying", "Running", "Scheduled", "Skipped", "Submitted", "Success", "Timedout", "Triggerfailed"],
    config: {{
      url: "{web_hook_url}"
    }}
  }}) {{
    id
  }}
}}
"""
something like this:
create_cloud_hook = f"""
mutation {{
  create_cloud_hook(input: {{
    type: WEBHOOK,
    name: "{cloud_hook_name}",
    version_group_id: "{version_group_id}",
    states: ["All"],
    config: {{
      url: "{web_hook_url}"
    }}
  }}) {{
    id
  }}
}}
"""
n

nicholas

05/20/2020, 5:23 PM
Hi @Mark McDonald! This is available in the UI but iirc you want to do this on flow registration, correct?
j

Jeremiah

05/20/2020, 5:25 PM
I think we don’t advertise this well — I think if you pass no states it means “all states”
:upvote: 1
I think we should revisit how we allow specification of matching states; for example maybe you supply a state and optionally whether all subclasses should be included
states: ['State'], include_subclasses: true
c

Chris White

05/20/2020, 5:27 PM
As a workaround for now:
from prefect.engine.state import State

[s.__name__ for s in State.children()]
should give you a complete list!
👍 1
:upvote: 1
j

Jeremiah

05/20/2020, 5:30 PM
Good news, as I check my own code (😬), I believe we already match on subclasses, so if you pass ‘STATE’ as the sole state, I’m pretty sure it would actually already work — i need to double check this though! Making a reminder for myself to confirm later today
m

Mark McDonald

05/20/2020, 5:40 PM
Thanks for the response @Jeremiah. I tried passing in "STATE". The webhook was successfully created. However, it didn't actually add any states to the configuration
Chris's work around is working for me. Thanks all!
😄 3
j

Jeremiah

05/20/2020, 11:00 PM
Got it! I think that might just be some crossed wire between the UI and the logic in the API — if no states are specified, internally we trigger on all states. But I think we can be better about that!