Runic.Workflow.HookEvent (Runic v0.1.0-alpha.7)

Copy Markdown View Source

Event struct passed to hooks during execution.

This provides a uniform interface for hooks across all node types, eliminating the need for workflow access during the execute phase.

Fields

  • :timing - :before or :after indicating when the hook is running
  • :node - The node struct being executed (Step, Condition, etc.)
  • :node_hash - Hash of the node for quick identification
  • :input_fact - The input fact triggering this execution
  • :result - For after hooks: the result of execution (Fact, boolean, etc.)

Example

# New-style hook (arity-2, workflow-free)
fn %HookEvent{timing: :before, node: step}, ctx ->
  Logger.info("Executing step #{step.name}")
  :ok
end

# Hook returning an apply_fn for workflow modifications
fn %HookEvent{timing: :after, result: fact}, _ctx ->
  {:apply, fn workflow ->
    Workflow.add(workflow, some_step, to: fact)
  end}
end

Summary

Functions

Creates an after-hook event with the execution result.

Creates a before-hook event.

Types

t()

@type t() :: %Runic.Workflow.HookEvent{
  input_fact: Runic.Workflow.Fact.t(),
  node: struct(),
  node_hash: integer(),
  result: term() | nil,
  timing: timing()
}

timing()

@type timing() :: :before | :after

Functions

after_exec(node, input_fact, result)

@spec after_exec(struct(), Runic.Workflow.Fact.t(), term()) :: t()

Creates an after-hook event with the execution result.

before(node, input_fact)

@spec before(
  struct(),
  Runic.Workflow.Fact.t()
) :: t()

Creates a before-hook event.