Get Last completed result

Hi,

I cannot seem to figure out how to get the last completed result for a Schedule workflow in the python SDK.

Does anyone have a pointer on how to do that?

I primarily want to get the time the workflow ran last time.

Thanks!

I primarily want to get the time the workflow ran last time.

You can get the last start_workflow timestamp from ScheduleActionResult: https://github.com/temporalio/api/blob/master/temporal/api/schedule/v1/message.proto#L332-L333

From Python SDK (modified from samples-python):

async def main():
    client = await Client.connect("localhost:7233")
    handle = client.get_schedule_handle(
        "workflow-schedule-id",
    )

    desc = await handle.describe()

    print(f"Last action: {desc.info.recent_actions[-1]}")

Output:

Last action: ScheduleActionResult(scheduled_at=datetime.datetime(2023, 9, 4, 1, 14, tzinfo=datetime.timezone.utc), started_at=datetime.datetime(2023, 9, 4, 1, 14, 0, 39888, tzinfo=datetime.timezone.utc), action=ScheduleActionExecutionStartWorkflow(workflow_id='schedules-workflow-id-2023-09-04T01:14:00Z', first_execution_run_id='585b8221-3830-4a72-ab18-67e305f9d285'))

If you want to get internal state from a completed workflow use Workflow Query.

Thanks for the reply

Is there a way to do this from inside a running workflow without instantiating another client? Or is this the canonical way?

Thanks!

Temporal client calls (or any other networked client calls) cannot be done from inside a workflow, and we do not have primitives for accessing schedules from inside a workflow. You can do this in an activity. You don’t have to instantiate another client, just set your client as class state and access via an activity method on the class (like this example).

Perfect, thanks so much for the tips!