Class: RigidWorkflow::Signal

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/rigid_workflow/signal.rb

Overview

Represents a signal for inter-step communication. Supports waiting with optional timeout and payload exchange.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.process!(signal, payload) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/models/rigid_workflow/signal.rb', line 40

def self.process!(signal, payload)
  return if signal.received?

  signal.update!(received_at: Time.current, payload: payload)
  RigidWorkflow.instrument(
    "signal.received",
    run_id: signal.rigid_workflow_run_id,
    signal_id: signal.id,
    signal_name: signal.name
  )
  Orchestrator.schedule(signal.workflow_run)
end

.process_signal(signal_id) ⇒ Boolean

Returns True if signal was processed successfully.

Parameters:

  • signal_id (Integer)

    The signal ID to process

Returns:

  • (Boolean)

    True if signal was processed successfully



58
59
60
61
62
63
64
65
66
67
68
# File 'app/models/rigid_workflow/signal.rb', line 58

def process_signal(signal_id)
  signal = RigidWorkflow::Signal.find_by(id: signal_id)
  return false if signal.nil? || signal.received?

  run = signal.workflow_run
  return false if !run.present? || run.finished?

  signal.update!(received_at: Time.current)
  RigidWorkflow::Orchestrator.schedule(run)
  true
end

Instance Method Details

#expired?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'app/models/rigid_workflow/signal.rb', line 36

def expired?
  expires_at.present? && expires_at <= Time.current
end

#received?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'app/models/rigid_workflow/signal.rb', line 32

def received?
  received_at.present?
end