1. Concepts
  2. State Hooks

Concepts

State Hooks

State hooks are a way to add action components (tasks/notifications/metrics) dynamically to actions when a stub is in a state, when it enters a state, or when it exits a state.

Introduction

There are three available state hook types, with each type adding your specified action components dynamically to actions depending on the state hook type and the state behaviour for running the action.

  • in_state: Action components are added to any action that runs while the stub is in this state.
  • on_exit_state: Action components are added to the action that results in exiting this state.
  • on_enter_state: Action components are added to the action that results in entering this state.

There can be state hooks in the "from state" and the "to state".
The multiple state hooks' action components will all be appended to the running action's action components in the order of priority above.

Here is an example scenario with example states, tasks, notifications and an action to help explain how things fit together more clearly:

Example

Example structure
        state-a:
  state_hooks:
    in_state:
      tasks: in_state_a_task
    on_exit_state:
      tasks: on_exit_state_a_task

action_a:
  tasks:
    - action_task_1
    - action_task_2
  notifications:
    - action_notification_1

state-b:
  state_hooks:
    on_enter_state:
      notifications: on_enter_state_b_notification
    on_exit_state:
      tasks: on_exit_state_b_task

      

When action_a changes the state of a stub from state_a to state_b, the order in which action components run on that action is as follows:

Tasks:

  1. action_task_1
  2. action_task_2
  3. in_state_a_task
  4. on_exit_state_a_task

Notifications:

  1. action_notification_1
  2. on_enter_state_b_notification

How to configure state hooks

See the state hooks page for more information on how to configure and use state hooks.