<@U06RKAMK0UC> How do you check the execution stat...
# ask-ai
b
@ancient-wolf-19325 How do you check the execution status of a workflow submitted using FlyteRemote
j
To check the execution status of a workflow submitted using
FlyteRemote
, you can use the
sync_execution
method. This method updates the state of the execution object with the latest status from the Flyte backend. Here's a basic example:
Copy code
from flytekit.remote import FlyteRemote

# Initialize FlyteRemote
remote = FlyteRemote(config=Config.for_endpoint(endpoint="flyte.example.net"), default_project="flytesnacks", default_domain="development")

# Fetch the execution
execution = remote.fetch_execution(name="execution_id", project="flytesnacks", domain="development")

# Sync the execution to get the latest status
synced_execution = remote.sync_execution(execution, sync_nodes=True)

# Check if the execution is done
if synced_execution.is_done:
    print("Execution is complete.")
else:
    print("Execution is still in progress.")
Would you like more detail on this process? Sources: - Inspecting executions - FlyteWorkflowExecution API πŸ‘ 0 button πŸ‘Ž 0 button πŸ’‘ Hint: Mention @runllm in the thread for followups.
b
@ancient-wolf-19325 I need to know if the workflow failed or succeeded when a workflow is submitted using FlyteRemote
j
To determine if a workflow submitted using
FlyteRemote
has failed or succeeded, you can check the
closure.phase
attribute of the
FlyteWorkflowExecution
object after syncing it. Here's how you can do it:
Copy code
from flytekit.remote import FlyteRemote
from flytekit.models.core.execution import WorkflowExecutionPhase

# Initialize FlyteRemote
remote = FlyteRemote(config=Config.for_endpoint(endpoint="flyte.example.net"), default_project="flytesnacks", default_domain="development")

# Fetch the execution
execution = remote.fetch_execution(name="execution_id", project="flytesnacks", domain="development")

# Sync the execution to get the latest status
synced_execution = remote.sync_execution(execution, sync_nodes=True)

# Check the phase of the execution
phase = synced_execution.closure.phase
if phase == WorkflowExecutionPhase.SUCCEEDED:
    print("Execution succeeded.")
elif phase == WorkflowExecutionPhase.FAILED:
    print("Execution failed.")
else:
    print(f"Execution is in {WorkflowExecutionPhase.enum_to_string(phase)} phase.")
Would you like more detail on this process? Sources: - FlyteRemote.sync_execution πŸ‘ 0 button πŸ‘Ž 0 button πŸ’‘ Hint: Mention @runllm in the thread for followups.
f
@brief-family-9488 if you use
exe = remote.execute()
then you can simply say
Copy code
exe = exe.wait()
or you can say
exe.sync()
b
sure, but that would be blocking. It would be nice to have a non-blocking way e.g. polling for status every few minutes until job completes
f
That’s possible with using sync
Sync just polls once
You can call it however