Callbacks (Customizing the Client Logic)

This is for advanced users of the HQS Tasks client, and therefore only documented very briefly.

You can add custom logic to some events during the procedure of executing tasks and waiting for their results.

Currently, the client logic has the following "events":

  • creating
  • submitted
  • reattached
  • progress
  • finished
  • cache_write
  • cache_hit
  • cache_miss
  • cache_ignored
  • backend_initialized
  • interrupt_waiting

The corresponding callbacks are named with an additional on_ prefix, and are available in the configuration object's top level (e.g. global_config.on_finished for the finished event).

To add behavior to an event, you register a function as a callback function to that event by simply decorating your custom function with that callback object.

Here is an example for a callback function which is to be invoked for any finished task execution:

from hqs_task_execution.config import global_config
from hqs_core_models import TaskExecutionRequest

@global_config.on_finished
def on_finished_task(request: TaskExecutionRequest) -> None:
    print(f"Task `{request.task_name}` just finished.")

When using an IDE which is capable of providing good support for the code model, you'll see the parameters the callback function can consume by inspecting the signature / docstring of the callback object (in that case global_config.on_finished).