Class: Ruote::BlockParticipant

Inherits:
Object
  • Object
show all
Includes:
LocalParticipant
Defined in:
lib/ruote/part/block_participant.rb

Overview

One of the simplest participants. Simply passes a workitem to a block of ruby code.

engine.register_participant :alpha do |workitem|
  workitem.fields['time'] = Time.now
end

This participant implicitely replies to the engine when the block execution is over.

You can pass the flow_expression (participant expression) as well.

engine.register_participant :alpha do |workitem, flow_exp|
  workitem.fields['amount'] = flow_exp.lookup_variable('amount')
end

do_not_thread

By default, this participant (like most other participants) is executed in its own thread.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from LocalParticipant

#re_dispatch, #unschedule_re_dispatch

Methods included from ReceiverMixin

#applied_workitem, #fetch_flow_expression, #launch, #receive, #reply, #reply_to_engine, #sign

Constructor Details

#initialize(opts) ⇒ BlockParticipant

Returns a new instance of BlockParticipant.



57
58
59
60
# File 'lib/ruote/part/block_participant.rb', line 57

def initialize(opts)

  @opts = opts
end

Instance Attribute Details

#contextObject

Returns the value of attribute context.



55
56
57
# File 'lib/ruote/part/block_participant.rb', line 55

def context
  @context
end

Instance Method Details

#accept?(workitem) ⇒ Boolean

Returns:

  • (Boolean)


97
98
99
100
101
102
103
104
# File 'lib/ruote/part/block_participant.rb', line 97

def accept?(workitem)

  if block = get_block('accept?')
    block.call(workitem)
  else
    true
  end
end

#cancel(fei, flavour) ⇒ Object



83
84
85
86
87
88
# File 'lib/ruote/part/block_participant.rb', line 83

def cancel(fei, flavour)

  if block = get_block('on_cancel')
    block.call(fei, flavour)
  end
end

#consume(workitem) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/ruote/part/block_participant.rb', line 62

def consume(workitem)

  block = get_block('on_workitem', 'block')

  r = if block.arity == 1

    block.call(workitem)

  else

    block.call(
      workitem, Ruote::Exp::FlowExpression.fetch(@context, workitem.h.fei))
  end

  if r != nil && r != workitem
    workitem.result = (Rufus::Json.dup(r) rescue nil)
  end

  reply_to_engine(workitem)
end

#do_not_thread(workitem) ⇒ Object



106
107
108
109
110
111
112
113
114
115
# File 'lib/ruote/part/block_participant.rb', line 106

def do_not_thread(workitem)

  dnt = @opts['do_not_thread']

  return dnt unless dnt.is_a?(String)

  block = get_block('do_not_thread')

  block.call(workitem)
end

#on_reply(workitem) ⇒ Object



90
91
92
93
94
95
# File 'lib/ruote/part/block_participant.rb', line 90

def on_reply(workitem)

  if block = get_block('on_reply')
    block.call(workitem)
  end
end