Gracefully cancel job#

When a Saturn Worker die or timeout, it will stop listening for an executor result. In these cases, it might be better to let the executor gracefully stop its job. This can be achieved by looking at a CancellationToken passed to the pipeline. Note that this feature is only supported with ARQ executors.

cancel.py#
from saturn_engine.core.pipeline import CancellationToken

def progress_work(message: str) -> bool: ...

def can_cancel(message: str, token: CancellationToken) -> None:
    while not token.is_cancelled:
        if progress_work(message):
            break

This is achieved by adding an argument with type annotation of CancellationToken. This object exposes the is_cancelled property or the threading.Event object with the event property.