Signature API Reference¶
This page provides detailed API documentation for task signature functionality in MageFlow.
mageflow.asign(task, **options)¶
Create a new task signature.
Parameters:
- task (str | HatchetTaskType): Task name (string) or HatchetTask instance to create signature for
- **options: Additional signature options including:
- kwargs: Dictionary of task parameters
- creation_time: Timestamp when signature was created
- model_validators: Validation models for task input
- success_callbacks: List of task IDs to execute on success
- error_callbacks: List of task IDs to execute on error
- task_status: Initial status for the task
Example:
TaskSignature¶
The main signature class that manages task execution and lifecycle.
Properties¶
task_name: Name of the taskkwargs: Dictionary of task parameterscreation_time: When the signature was createdsuccess_callbacks: Tasks executed when task completes successfullyerror_callbacks: Tasks executed when task failstask_status: Current status informationkey: Unique identifier for the signature
Class Methods¶
delete_signature(task_id)¶
Delete a signature by ID.
Instance Methods¶
aio_run_no_wait(msg)¶
Execute the task asynchronously without waiting for completion.
Parameters:
- msg (BaseModel): Message object to pass to the task
remove(with_error, with_success)¶
Remove the signature and optionally its callbacks.
Lifecycle Management¶
suspend()¶
Suspend task execution before it starts.
Sets task status to SUSPENDED. The task will not execute until resumed.
resume()¶
Resume a suspended task.
Restores the previous status and re-triggers execution if needed.
interrupt()¶
Aggressively interrupt task execution.
pause_task(pause_type)¶
Pause task with specified action type.
Parameters:
- pause_type (PauseActionTypes): Either SUSPEND or INTERRUPT
Helper Functions¶
mageflow.load_signature(key)¶
Load stored signature by ID from redis.
mageflow.resume_task(task_id) / mageflow.resume(task_id)¶
mageflow.pause(task_id)¶
mageflow.remove(task_id)¶
mageflow.lock_task(task_id)¶
Create a lock of the task signature, the signature will not be deleted nor change status while locked.
Warning
This function can be dangerous as signatures wont be able to be deleted or change status while locked. It may prevent task from finishing, causing timeout.