Skip to content

checkmate

Extension of the basic CheckMateEngine that adds RDBMS persistence via bind/unbind hooks.

Attributes

DEFAULT_QUEUE_NAME module-attribute

DEFAULT_QUEUE_NAME = 'default'

Classes

CheckMate

CheckMate(
    checkmate_factory: Callable[..., CheckMate],
    stage_templates: List[STAGE] | None = None,
    task_id: str | None = None,
    description: str | None = None,
    no_lock: bool = False,
    retry_policy: RetryPolicy | None = None,
    max_attempts: int | None = None,
    bind_lock_timeout: int | None = None,
    auto_cleanup: bool | None = None,
    force_create: bool = False,
    queue: str = DEFAULT_QUEUE_NAME,
    tags: List[str] | None = None,
)

Bases: CheckMateEngine[STAGE, STAGE_RESULT]

ManagedTask extends TaskEngine to add RDBMS persistence via bind/unbind hooks.

This class provides additional functionality to bind and unbind tasks with a relational database management system (RDBMS). It ensures that task states are persisted in the database during the bind and unbind operations.

Attributes:

Initializes a ManagedTask instance.

This constructor sets up a ManagedTask with optional stage templates, task ID, description, and various configuration options. It ensures that the task is properly configured for RDBMS persistence and task engine operations.

Parameters:

  • stage_templates (List[STAGE] | None, default: None ) –

    Optional list of stage templates.

  • task_id (str | None, default: None ) –

    Optional unique identifier for the task.

  • description (str | None, default: None ) –

    Optional description of the task.

  • no_lock (bool, default: False ) –

    Boolean flag to indicate if locking should be disabled.

  • retry_policy (RetryPolicy | None, default: None ) –

    Optional retry policy for the task.

  • max_attempts (int | None, default: None ) –

    Optional maximum number of attempts for the task.

  • bind_lock_timeout (int | None, default: None ) –

    Optional timeout for bind lock.

  • auto_cleanup (bool | None, default: None ) –

    Optional flag to enable automatic cleanup.

  • force_create (bool, default: False ) –

    Boolean flag to indicate if the task should be created if it doesn’t exist.

  • queue (str, default: DEFAULT_QUEUE_NAME ) –

    Queue name for the task.

Example
with ManagedTask(
stage_templates=[
    NOPStage(
    stage_name="stage1",
    description="No-op stage for testing",
    state=BaseStageState(),
    ),
    NOPStage(
    stage_name="stage2",
    description="No-op stage for testing",
    state=BaseStageState(),
    ),
],
description="Sample task",
no_lock=True,
retry_policy=RetryPolicy.RETRY,
max_attempts=3,
bind_lock_timeout=5,
auto_cleanup=False
) as task:
# Perform task operations here...

Attributes

checkmate_factory instance-attribute
description instance-attribute
description = description
queue instance-attribute
queue = queue
tags instance-attribute
tags = tags

Functions

bind
bind() -> None

Bind the task to the current process.

This method ensures that the task is persisted in the RDBMS. If the task does not exist in the database, it will be created.

state_update_hook
state_update_hook() -> None
unbind
unbind(clean: bool = False) -> None

Unbind the task from the current process.

This method ensures that the task state is updated in the RDBMS. If the task does not exist in the database, a warning is logged.

Parameters:

  • clean (bool, default: False ) –

    Boolean flag to indicate if the task should be marked as cleaned.

Functions