Signals

All django-routines specific Signals are defined here.

All signals contain a routine field that holds the name of the routine in question.

django_routines.signals.routine_started = <django.dispatch.dispatcher.Signal object>

Signal sent when a routine is started, but before any commands have been run.

Signature: (sender, routine, **kwargs)

Parameters:
  • sender (RoutineCommand) – An instance of the running routine command.

  • routine (str) – The name of the routine being started.

  • kwargs (Dict[str, Any]) – The CLI options passed to the routine.

django_routines.signals.routine_failed = <django.dispatch.dispatcher.Signal object>

Signal sent when a routine is completed successfully. This will be called before the exception is raised out of the command stack.

Signature: (sender, routine, failed_command, exception, **kwargs) -> bool

Tip

If you raise an ExitEarly exception from a connected receiver, the routine will not propagate the exception and exit early gracefully.

Parameters:
  • sender (RoutineCommand) – An instance of the running routine command.

  • routine (str) – The name of the routine that failed.

  • failed_command (int) – The plan index of the command that failed. See Plan Indexes.

  • exception (Exception) – The exception that caused the routine to fail.

  • kwargs (Dict[str, Any]) – The CLI options passed to the routine.

Returns:

If any connected receiver to this signal returns a truthy value the routine will proceed.

Return type:

Optional[bool]

django_routines.signals.routine_finished = <django.dispatch.dispatcher.Signal object>

Signal sent when a routine is completed successfully.

Signature: (sender, routine, early_exit, last_command, **kwargs) -> bool

Parameters:
  • sender (RoutineCommand) – An instance of the running routine command.

  • routine (str) – The name of the routine that completed.

  • early_exit (bool) – True if a post hook triggered an early exit.

  • last_command (Optional[int]) – The plan index of the last command that was run in the routine (if any!). See Plan Indexes.

  • kwargs (Dict[str, Any]) – The CLI options passed to the routine.

Plan Indexes

When signals include a plan index, it refers to the index of the command in the routine’s plan. The index will refer to either a ManagementCommand instance or a SystemCommand instance, depending on the type of command in the plan. You can access the command object from the plan and index like so:

import typing as t
from django.core.signals import Signal
from django_routines.management.commands.routine import Command as RoutineCommand

def handle_routine_failed(
   sender: RoutineCommand,            # the routine command instance (holds the plan)
   routine: str,                      # the name of the routine
   failed_command: int,               # the index of the command that failed in the plan
   exception: t.Optional[Exception],  # the exception that caused the failure
   signal: Signal,                    # the signal instance
   **kwargs                           # CLI options passed to the routine
):
    sender.plan[failed_command].command_name  # access the command name