Darren Liu
01/25/2023, 3:05 AMPeyton Runyan
01/25/2023, 3:30 PMDarren Liu
01/26/2023, 1:52 AMPeyton Runyan
01/27/2023, 1:09 AMclient.create_flow_run_from_deployment(
game_deployment,
parameters = {
'game_id': <id>,
'state': None
}
)
You would then have your flow, which would take the parameters of gamde_id
and state
. At the end of the flow, it would hit the automations API to schedule a new deployment with the state
@flow
def my_logic(game_id: UUID, state: dict):
info = get_info()
if info == state["info"]:
return cleanup()
state["info"] = processing_logic()
run_automation(id=id, state=state)
We currently don't have client methods for creating automations, so you would have to wrap an API call, but it's documented here, and you can get additional help here in the slack.
https://docs.prefect.io/ui/automations/#create-an-automationgames = get_games():
for game in games():
client.create_flow_run_from_deployment(
long_running_game_deployment,
parameters = {
'game_id': <id>,
`pool_interval': <some_int>,
}
)
But then instead of having a flow that kicks off another flow each loop, you just have that flow loop for the duration of the game
@flow
async def game_loop(game_id: UUID, poll_interval: int):
while True:
game_info = get_game_info(game_id)
if is_finished(game_info):
break()
perform_logic()
asyncio.sleep(poll_interval)
cleanup()
Darren Liu
01/31/2023, 7:32 AM