Skip to content

Don't terminate listener on a raised exception #3

@MaxwellGBrown

Description

@MaxwellGBrown

Currently the listener bubbles up exceptions after sending a task failure, which will terminate ActivityWorker.listen().

try:
    print(f"Performing {self.activity_name}")
    with heartbeat:
        task_input = json.loads(task["input"])
        output = self.activity_fxn(**task_input)
except (Exception, KeyboardInterrupt) as error:
    *_, raw_traceback = sys.exc_info()
    formatted_traceback = traceback.format_tb(raw_traceback)

    print(f"{self.activity_name} failed!")
    self.stepfunctions.send_task_failure(
        taskToken=task["taskToken"],
        error=str(error)[:256],
        cause="\n".join(formatted_traceback),
    )

    raise

...however, StepFunctions allows you to catch raised exceptions and transition to a different state.

If this is something you are expecting to happen in your Workflow, you shouldn't have to recreate your listener after catching an expected task failure.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions