Skip to content

Commit

Permalink
using sourcify for BlockParticipant - step 1
Browse files Browse the repository at this point in the history
motivation : http://groups.google.com/group/openwferu-users/browse_thread/thread/5cb41f958d91308b

step 2 is running a security check on the code befare evaluation.
  • Loading branch information
jmettraux committed Jan 30, 2011
1 parent 7675a47 commit 80a45f6
Show file tree
Hide file tree
Showing 54 changed files with 468 additions and 582 deletions.
7 changes: 7 additions & 0 deletions TODO.txt
Expand Up @@ -459,5 +459,12 @@
launch a process with a designed 'supervisor' ?

[ ] ci : ruote-amqp
[ ] ci : ruote-mongodb
[ ] ci : jruby

[ ] StorageParticipant#reply : raise if workitem not found ?
[ ] StorageParticipant#reply : accept fei ?

[ ] eft_18 weak with jruby-1.5.1


14 changes: 9 additions & 5 deletions lib/ruote/engine.rb
Expand Up @@ -521,14 +521,18 @@ def load_definition (path)
# containing the participant implementation. 'require' will load and eval
# the ruby code only once, 'load' each time.
#
def register_participant (regex, participant=nil, opts={}, &block)
def register_participant (regex, participant=nil, opts=nil, &block)

if participant.is_a?(Hash)
opts = participant
participant = nil
end

opts ||= {}

pa = @context.plist.register(regex, participant, opts, block)

@context.storage.put_msg(
'participant_registered',
'regex' => regex.to_s,
'engine_worker_only' => (pa != nil))
@context.storage.put_msg('participant_registered', 'regex' => regex.to_s)

pa
end
Expand Down
3 changes: 1 addition & 2 deletions lib/ruote/exp/fe_participant.rb
Expand Up @@ -167,8 +167,7 @@ def apply
'fei' => h.fei,
'participant_name' => h.participant_name,
'participant' => h.participant,
'workitem' => h.applied_workitem,
'for_engine_worker?' => (participant_info.class != Array))
'workitem' => h.applied_workitem)
end

def cancel (flavour)
Expand Down
27 changes: 19 additions & 8 deletions lib/ruote/part/block_participant.rb
Expand Up @@ -67,28 +67,39 @@ class BlockParticipant
include LocalParticipant

attr_accessor :context
attr_accessor :do_not_thread

def initialize (block, opts)
def initialize (opts)

@opts = opts
@block = block
@do_not_thread = false
end

def do_not_thread

@opts['do_not_thread']
end

def consume (workitem)

r = if @block.arity == 1
block = @opts['block']

#block = eval(block, @context.send(:binding))
# doesn't work with ruby 1.9.2-p136

block = eval(block, @context.instance_eval { binding })
# works OK with ruby 1.8.7-249 and 1.9.2-p136

# TODO : security !!

r = if block.arity == 1

@block.call(workitem)
block.call(workitem)
else

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

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

Expand Down
91 changes: 0 additions & 91 deletions lib/ruote/part/hash_participant.rb

This file was deleted.

20 changes: 20 additions & 0 deletions lib/ruote/part/storage_participant.rb
Expand Up @@ -119,6 +119,9 @@ def fetch (fei)

# Removes the workitem from the in-memory hash and replies to the engine.
#
# TODO : should it raise if the workitem can't be found ?
# TODO : should it accept just the fei ?
#
def reply (workitem)

# TODO: change method name (receiver mess cleanup)
Expand Down Expand Up @@ -287,6 +290,23 @@ def self.matches? (hwi, pname, criteria)
true
end

# Mostly a test method. Returns a Hash were keys are participant names
# and values are lists of workitems.
#
def per_participant

inject({}) { |h, wi| (h[wi.participant_name] ||= []) << wi; h }
end

# Mostly a test method. Returns a Hash were keys are participant names
# and values are integers, the count of workitems for a given participant
# name.
#
def per_participant_count

per_participant.inject({}) { |h, (k, v)| h[k] = v.size; h }
end

protected

# Fetches all the workitems. If there is a @store_name, will only fetch
Expand Down
1 change: 0 additions & 1 deletion lib/ruote/participant.rb
@@ -1,5 +1,4 @@

require 'ruote/part/hash_participant'
require 'ruote/part/storage_participant'
require 'ruote/part/no_op_participant'
require 'ruote/part/null_participant'
Expand Down
11 changes: 3 additions & 8 deletions lib/ruote/storage/hash_storage.rb
Expand Up @@ -111,16 +111,11 @@ def delete (doc)

doc['_rev'] ||= 0

if prev['_rev'] == drev
return prev if prev['_rev'] != drev

@h[doc['type']].delete(doc['_id'])
@h[doc['type']].delete(doc['_id'])

nil

else

prev
end
nil # success
end
end

Expand Down

0 comments on commit 80a45f6

Please sign in to comment.