Class: Fractor::Workflow::ExecutionHooks

Inherits:
Object
  • Object
show all
Defined in:
lib/fractor/workflow/execution_hooks.rb

Overview

Manages lifecycle hooks for workflow execution. Allows registering callbacks for workflow/job lifecycle events.

Instance Method Summary collapse

Constructor Details

#initializeExecutionHooks

Returns a new instance of ExecutionHooks.



8
9
10
# File 'lib/fractor/workflow/execution_hooks.rb', line 8

def initialize
  @hooks = Hash.new { |h, k| h[k] = [] }
end

Instance Method Details

#register(event) {|Object| ... } ⇒ Object

Register a callback for a specific event.

Examples:

Register a workflow start hook

hooks.register(:workflow_start) do |workflow|
  puts "Workflow starting: #{workflow.class.workflow_name}"
end

Parameters:

  • event (Symbol)

    The event to hook into

Yields:

  • (Object)

    Block to execute when event is triggered



21
22
23
# File 'lib/fractor/workflow/execution_hooks.rb', line 21

def register(event, &block)
  @hooks[event] << block
end

#trigger(event, *args) ⇒ Object

Trigger all callbacks registered for an event.

Examples:

Trigger workflow completion

hooks.trigger(:workflow_complete, result)

Parameters:

  • event (Symbol)

    The event to trigger

  • args (Array)

    Arguments to pass to the callbacks



32
33
34
35
36
# File 'lib/fractor/workflow/execution_hooks.rb', line 32

def trigger(event, *args)
  @hooks[event].each do |hook|
    hook.call(*args)
  end
end