https://prefect.io logo
Title
m

Mansour Zayer

04/04/2023, 8:44 PM
Hello. I have a flow that calls 3 other subflows. These subflows can enter
Cancelled
state in certain conditions (expected behavior). When any of them enters
Cancelled
state and the rest complete, the main flow also enters
Canceled
state. How can I make the main flow succeed? This is my code
@flow()
def main_flow():
  subflows = (subflow1, subflow2, subflow3)  
    for subflow in subflows:
      try:
        subflow()
      except CancelledRun:
        continue
When the first flow cancels, I get something like this
Finished in state Cancelled('1/3 states cancelled.')
and the main flow state becomes Cancelled too. Thanks
For more context, the subflows Cancel their run using this mechanism:
@task
def my_task():
  if condition:
    return Cancelled()
@flow
def subflow():
  my_task()
Is there a better way to do it?
🤦 I think I simply need to do
for subflow in subflows:
      try:
        subflow()
      except CancelledRun:
        continue
      except Exception as e:
        ...
else:
  Completed()
👍 1
d

Deceivious

04/05/2023, 8:30 AM
Well did that work? 😄
m

Mansour Zayer

04/05/2023, 6:29 PM
Yes it works