repo
stringlengths 5
58
| path
stringlengths 9
168
| func_name
stringlengths 9
130
| original_string
stringlengths 66
10.5k
| language
stringclasses 1
value | code
stringlengths 66
10.5k
| code_tokens
list | docstring
stringlengths 8
16k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 94
266
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
jmettraux/ruote | lib/ruote/exp/flow_expression.rb | Ruote::Exp.FlowExpression.pre_apply_child | def pre_apply_child(child_index, workitem, forget)
child_fei = h.fei.merge(
'expid' => "#{h.fei['expid']}_#{child_index}",
'subid' => Ruote.generate_subid(h.fei.inspect))
h.children << child_fei unless forget
msg = {
'fei' => child_fei,
'tree' => tree.last[child_index],
'parent_id' => forget ? nil : h.fei,
'variables' => forget ? compile_variables : nil,
'workitem' => workitem
}
msg['forgotten'] = true if forget
msg
end | ruby | def pre_apply_child(child_index, workitem, forget)
child_fei = h.fei.merge(
'expid' => "#{h.fei['expid']}_#{child_index}",
'subid' => Ruote.generate_subid(h.fei.inspect))
h.children << child_fei unless forget
msg = {
'fei' => child_fei,
'tree' => tree.last[child_index],
'parent_id' => forget ? nil : h.fei,
'variables' => forget ? compile_variables : nil,
'workitem' => workitem
}
msg['forgotten'] = true if forget
msg
end | [
"def",
"pre_apply_child",
"(",
"child_index",
",",
"workitem",
",",
"forget",
")",
"child_fei",
"=",
"h",
".",
"fei",
".",
"merge",
"(",
"'expid'",
"=>",
"\"#{h.fei['expid']}_#{child_index}\"",
",",
"'subid'",
"=>",
"Ruote",
".",
"generate_subid",
"(",
"h",
".",
"fei",
".",
"inspect",
")",
")",
"h",
".",
"children",
"<<",
"child_fei",
"unless",
"forget",
"msg",
"=",
"{",
"'fei'",
"=>",
"child_fei",
",",
"'tree'",
"=>",
"tree",
".",
"last",
"[",
"child_index",
"]",
",",
"'parent_id'",
"=>",
"forget",
"?",
"nil",
":",
"h",
".",
"fei",
",",
"'variables'",
"=>",
"forget",
"?",
"compile_variables",
":",
"nil",
",",
"'workitem'",
"=>",
"workitem",
"}",
"msg",
"[",
"'forgotten'",
"]",
"=",
"true",
"if",
"forget",
"msg",
"end"
]
| Used locally but also by ConcurrenceExpression, when preparing children
before they get applied. | [
"Used",
"locally",
"but",
"also",
"by",
"ConcurrenceExpression",
"when",
"preparing",
"children",
"before",
"they",
"get",
"applied",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/exp/flow_expression.rb#L965-L983 | train |
jmettraux/ruote | lib/ruote/exp/flow_expression.rb | Ruote::Exp.FlowExpression.apply_child | def apply_child(child_index, workitem, forget=false)
msg = pre_apply_child(child_index, workitem, forget)
persist_or_raise unless forget
# no need to persist the parent (this) if the child is to be forgotten
@context.storage.put_msg('apply', msg)
end | ruby | def apply_child(child_index, workitem, forget=false)
msg = pre_apply_child(child_index, workitem, forget)
persist_or_raise unless forget
# no need to persist the parent (this) if the child is to be forgotten
@context.storage.put_msg('apply', msg)
end | [
"def",
"apply_child",
"(",
"child_index",
",",
"workitem",
",",
"forget",
"=",
"false",
")",
"msg",
"=",
"pre_apply_child",
"(",
"child_index",
",",
"workitem",
",",
"forget",
")",
"persist_or_raise",
"unless",
"forget",
"@context",
".",
"storage",
".",
"put_msg",
"(",
"'apply'",
",",
"msg",
")",
"end"
]
| Used by expressions when, well, applying a child expression of theirs. | [
"Used",
"by",
"expressions",
"when",
"well",
"applying",
"a",
"child",
"expression",
"of",
"theirs",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/exp/flow_expression.rb#L987-L995 | train |
jmettraux/ruote | lib/ruote/exp/flow_expression.rb | Ruote::Exp.FlowExpression.leave_tag | def leave_tag(workitem)
unset_variable(h.tagname)
Ruote::Workitem.new(workitem).send(:remove_tag, h.tagname)
@context.storage.put_msg(
'left_tag',
'tag' => h.tagname,
'full_tag' => h.full_tagname,
'fei' => h.fei,
'workitem' => workitem)
return unless h.full_tagname # for backward compatibility
r = root
return unless r && r.variables # might happen
r.variables.delete(h.full_tagname)
state = case (h.trigger || h.state)
when 'on_cancel' then 'cancelled'
when 'on_error' then 'failed'
when 'on_timeout' then 'timed out'
when 'on_re_apply' then nil
when 'cancelling' then 'cancelled'
when 'dying' then 'killed'
else nil
end
(r.variables['__past_tags__'] ||= []) << [
h.full_tagname,
fei.sid,
state,
Ruote.now_to_utc_s,
Ruote.fulldup(h.variables)
# not fullduping here triggers a segfault at some point with YAJL
]
r.do_persist unless r.fei == self.fei
end | ruby | def leave_tag(workitem)
unset_variable(h.tagname)
Ruote::Workitem.new(workitem).send(:remove_tag, h.tagname)
@context.storage.put_msg(
'left_tag',
'tag' => h.tagname,
'full_tag' => h.full_tagname,
'fei' => h.fei,
'workitem' => workitem)
return unless h.full_tagname # for backward compatibility
r = root
return unless r && r.variables # might happen
r.variables.delete(h.full_tagname)
state = case (h.trigger || h.state)
when 'on_cancel' then 'cancelled'
when 'on_error' then 'failed'
when 'on_timeout' then 'timed out'
when 'on_re_apply' then nil
when 'cancelling' then 'cancelled'
when 'dying' then 'killed'
else nil
end
(r.variables['__past_tags__'] ||= []) << [
h.full_tagname,
fei.sid,
state,
Ruote.now_to_utc_s,
Ruote.fulldup(h.variables)
# not fullduping here triggers a segfault at some point with YAJL
]
r.do_persist unless r.fei == self.fei
end | [
"def",
"leave_tag",
"(",
"workitem",
")",
"unset_variable",
"(",
"h",
".",
"tagname",
")",
"Ruote",
"::",
"Workitem",
".",
"new",
"(",
"workitem",
")",
".",
"send",
"(",
":remove_tag",
",",
"h",
".",
"tagname",
")",
"@context",
".",
"storage",
".",
"put_msg",
"(",
"'left_tag'",
",",
"'tag'",
"=>",
"h",
".",
"tagname",
",",
"'full_tag'",
"=>",
"h",
".",
"full_tagname",
",",
"'fei'",
"=>",
"h",
".",
"fei",
",",
"'workitem'",
"=>",
"workitem",
")",
"return",
"unless",
"h",
".",
"full_tagname",
"r",
"=",
"root",
"return",
"unless",
"r",
"&&",
"r",
".",
"variables",
"r",
".",
"variables",
".",
"delete",
"(",
"h",
".",
"full_tagname",
")",
"state",
"=",
"case",
"(",
"h",
".",
"trigger",
"||",
"h",
".",
"state",
")",
"when",
"'on_cancel'",
"then",
"'cancelled'",
"when",
"'on_error'",
"then",
"'failed'",
"when",
"'on_timeout'",
"then",
"'timed out'",
"when",
"'on_re_apply'",
"then",
"nil",
"when",
"'cancelling'",
"then",
"'cancelled'",
"when",
"'dying'",
"then",
"'killed'",
"else",
"nil",
"end",
"(",
"r",
".",
"variables",
"[",
"'__past_tags__'",
"]",
"||=",
"[",
"]",
")",
"<<",
"[",
"h",
".",
"full_tagname",
",",
"fei",
".",
"sid",
",",
"state",
",",
"Ruote",
".",
"now_to_utc_s",
",",
"Ruote",
".",
"fulldup",
"(",
"h",
".",
"variables",
")",
"]",
"r",
".",
"do_persist",
"unless",
"r",
".",
"fei",
"==",
"self",
".",
"fei",
"end"
]
| Called when the expression is about to reply to its parent and wants
to get rid of its tags. | [
"Called",
"when",
"the",
"expression",
"is",
"about",
"to",
"reply",
"to",
"its",
"parent",
"and",
"wants",
"to",
"get",
"rid",
"of",
"its",
"tags",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/exp/flow_expression.rb#L1041-L1085 | train |
jmettraux/ruote | lib/ruote/util/filter.rb | Ruote.RuleSession.do_merge | def do_merge(field, target, value)
value = Rufus::Json.dup(value)
if target.is_a?(Array)
target.push(value)
elsif value.is_a?(Hash)
target.merge!(value)
else # deal with non Hash
target[field.split('.').last] = value
end
target.delete('~')
target.delete('~~')
end | ruby | def do_merge(field, target, value)
value = Rufus::Json.dup(value)
if target.is_a?(Array)
target.push(value)
elsif value.is_a?(Hash)
target.merge!(value)
else # deal with non Hash
target[field.split('.').last] = value
end
target.delete('~')
target.delete('~~')
end | [
"def",
"do_merge",
"(",
"field",
",",
"target",
",",
"value",
")",
"value",
"=",
"Rufus",
"::",
"Json",
".",
"dup",
"(",
"value",
")",
"if",
"target",
".",
"is_a?",
"(",
"Array",
")",
"target",
".",
"push",
"(",
"value",
")",
"elsif",
"value",
".",
"is_a?",
"(",
"Hash",
")",
"target",
".",
"merge!",
"(",
"value",
")",
"else",
"target",
"[",
"field",
".",
"split",
"(",
"'.'",
")",
".",
"last",
"]",
"=",
"value",
"end",
"target",
".",
"delete",
"(",
"'~'",
")",
"target",
".",
"delete",
"(",
"'~~'",
")",
"end"
]
| Used by both _merge_to and _merge_from | [
"Used",
"by",
"both",
"_merge_to",
"and",
"_merge_from"
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/util/filter.rb#L275-L289 | train |
jmettraux/ruote | lib/ruote/dboard/process_status.rb | Ruote.ProcessStatus.tags | def tags
variables ? Hash[variables.select { |k, v| Ruote.is_a_fei?(v) }] : nil
end | ruby | def tags
variables ? Hash[variables.select { |k, v| Ruote.is_a_fei?(v) }] : nil
end | [
"def",
"tags",
"variables",
"?",
"Hash",
"[",
"variables",
".",
"select",
"{",
"|",
"k",
",",
"v",
"|",
"Ruote",
".",
"is_a_fei?",
"(",
"v",
")",
"}",
"]",
":",
"nil",
"end"
]
| Returns a hash tagname => fei of tags set at the root of the process
instance.
Returns nil if there is no defined root expression. | [
"Returns",
"a",
"hash",
"tagname",
"=",
">",
"fei",
"of",
"tags",
"set",
"at",
"the",
"root",
"of",
"the",
"process",
"instance",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/dboard/process_status.rb#L153-L156 | train |
jmettraux/ruote | lib/ruote/dboard/process_status.rb | Ruote.ProcessStatus.all_tags | def all_tags
all_variables.remap do |(fei, vars), h|
vars.each { |k, v| (h[k] ||= []) << v if Ruote.is_a_fei?(v) }
end
end | ruby | def all_tags
all_variables.remap do |(fei, vars), h|
vars.each { |k, v| (h[k] ||= []) << v if Ruote.is_a_fei?(v) }
end
end | [
"def",
"all_tags",
"all_variables",
".",
"remap",
"do",
"|",
"(",
"fei",
",",
"vars",
")",
",",
"h",
"|",
"vars",
".",
"each",
"{",
"|",
"k",
",",
"v",
"|",
"(",
"h",
"[",
"k",
"]",
"||=",
"[",
"]",
")",
"<<",
"v",
"if",
"Ruote",
".",
"is_a_fei?",
"(",
"v",
")",
"}",
"end",
"end"
]
| Returns a hash tagname => array of feis of all the tags set in the process
instance. | [
"Returns",
"a",
"hash",
"tagname",
"=",
">",
"array",
"of",
"feis",
"of",
"all",
"the",
"tags",
"set",
"in",
"the",
"process",
"instance",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/dboard/process_status.rb#L161-L166 | train |
jmettraux/ruote | lib/ruote/dboard/process_status.rb | Ruote.ProcessStatus.wfid | def wfid
l = [ @expressions, @errors, @stored_workitems ].find { |l| l.any? }
l ? l.first.fei.wfid : nil
end | ruby | def wfid
l = [ @expressions, @errors, @stored_workitems ].find { |l| l.any? }
l ? l.first.fei.wfid : nil
end | [
"def",
"wfid",
"l",
"=",
"[",
"@expressions",
",",
"@errors",
",",
"@stored_workitems",
"]",
".",
"find",
"{",
"|",
"l",
"|",
"l",
".",
"any?",
"}",
"l",
"?",
"l",
".",
"first",
".",
"fei",
".",
"wfid",
":",
"nil",
"end"
]
| Returns the unique identifier for this process instance. | [
"Returns",
"the",
"unique",
"identifier",
"for",
"this",
"process",
"instance",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/dboard/process_status.rb#L197-L202 | train |
jmettraux/ruote | lib/ruote/dboard/process_status.rb | Ruote.ProcessStatus.position | def position
workitems.collect { |wi|
r = [ wi.fei.sid, wi.participant_name ]
params = (wi.fields['params'] || {}).dup
params.delete('ref')
if err = errors.find { |e| e.fei == wi.fei }
params['error'] = err.message
end
r << params
r
}
end | ruby | def position
workitems.collect { |wi|
r = [ wi.fei.sid, wi.participant_name ]
params = (wi.fields['params'] || {}).dup
params.delete('ref')
if err = errors.find { |e| e.fei == wi.fei }
params['error'] = err.message
end
r << params
r
}
end | [
"def",
"position",
"workitems",
".",
"collect",
"{",
"|",
"wi",
"|",
"r",
"=",
"[",
"wi",
".",
"fei",
".",
"sid",
",",
"wi",
".",
"participant_name",
"]",
"params",
"=",
"(",
"wi",
".",
"fields",
"[",
"'params'",
"]",
"||",
"{",
"}",
")",
".",
"dup",
"params",
".",
"delete",
"(",
"'ref'",
")",
"if",
"err",
"=",
"errors",
".",
"find",
"{",
"|",
"e",
"|",
"e",
".",
"fei",
"==",
"wi",
".",
"fei",
"}",
"params",
"[",
"'error'",
"]",
"=",
"err",
".",
"message",
"end",
"r",
"<<",
"params",
"r",
"}",
"end"
]
| Returns the 'position' of the process.
pdef = Ruote.process_definition do
alpha :task => 'clean car'
end
wfid = engine.launch(pdef)
sleep 0.500
engine.process(wfid) # => [["0_0", "alpha", {"task"=>"clean car"}]]
A process with concurrent branches will yield multiple 'positions'.
It uses #workitems underneath.
If you want to list all the expressions where the "flow currently is"
regardless they are participant expressions or errors, look at the
#leaves method. | [
"Returns",
"the",
"position",
"of",
"the",
"process",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/dboard/process_status.rb#L255-L271 | train |
jmettraux/ruote | lib/ruote/dboard/process_status.rb | Ruote.ProcessStatus.leaves | def leaves
expressions.inject([]) { |a, exp|
a.select { |e| ! exp.ancestor?(e.fei) } + [ exp ]
}
end | ruby | def leaves
expressions.inject([]) { |a, exp|
a.select { |e| ! exp.ancestor?(e.fei) } + [ exp ]
}
end | [
"def",
"leaves",
"expressions",
".",
"inject",
"(",
"[",
"]",
")",
"{",
"|",
"a",
",",
"exp",
"|",
"a",
".",
"select",
"{",
"|",
"e",
"|",
"!",
"exp",
".",
"ancestor?",
"(",
"e",
".",
"fei",
")",
"}",
"+",
"[",
"exp",
"]",
"}",
"end"
]
| Returns the expressions where the flow is currently, ak the leaves
of the execution tree.
Whereas #position only looks at participant expressions (and errors),
#leaves looks at any expressions that is a leave (which has no
child at this point).
Returns an array of FlowExpression instances. (Note that they may
have their attribute #error set). | [
"Returns",
"the",
"expressions",
"where",
"the",
"flow",
"is",
"currently",
"ak",
"the",
"leaves",
"of",
"the",
"execution",
"tree",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/dboard/process_status.rb#L283-L288 | train |
jmettraux/ruote | lib/ruote/dboard/process_status.rb | Ruote.ProcessStatus.workitems | def workitems
@expressions.select { |fexp|
#fexp.is_a?(Ruote::Exp::ParticipantExpression)
fexp.h.name == 'participant'
}.collect { |fexp|
Ruote::Workitem.new(fexp.h.applied_workitem)
}
end | ruby | def workitems
@expressions.select { |fexp|
#fexp.is_a?(Ruote::Exp::ParticipantExpression)
fexp.h.name == 'participant'
}.collect { |fexp|
Ruote::Workitem.new(fexp.h.applied_workitem)
}
end | [
"def",
"workitems",
"@expressions",
".",
"select",
"{",
"|",
"fexp",
"|",
"fexp",
".",
"h",
".",
"name",
"==",
"'participant'",
"}",
".",
"collect",
"{",
"|",
"fexp",
"|",
"Ruote",
"::",
"Workitem",
".",
"new",
"(",
"fexp",
".",
"h",
".",
"applied_workitem",
")",
"}",
"end"
]
| Returns a list of the workitems currently 'out' to participants
For example, with an instance of
Ruote.process_definition do
concurrence do
alpha :task => 'clean car'
bravo :task => 'sell car'
end
end
calling engine.process(wfid).workitems will yield two workitems
(alpha and bravo).
Warning : do not confuse the workitems here with the workitems held
in a storage participant or equivalent. The workitem returned here
are the workitems as they were right before being sent out to the
participant.
Note: the workitems handed out here are not "workitem documents",
they are extracted from the 'participant' expressions in the
expression trees not from the stored workitems lot, they cannot
be updated/proceeded via a storage participant. Consider them
"read only". | [
"Returns",
"a",
"list",
"of",
"the",
"workitems",
"currently",
"out",
"to",
"participants"
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/dboard/process_status.rb#L326-L334 | train |
jmettraux/ruote | lib/ruote/dboard/process_status.rb | Ruote.ProcessStatus.to_dot | def to_dot(opts={})
s = [ "digraph \"process wfid #{wfid}\" {" ]
@expressions.each { |e| s.push(*e.send(:to_dot, opts)) }
@errors.each { |e| s.push(*e.send(:to_dot, opts)) }
s << '}'
s.join("\n")
end | ruby | def to_dot(opts={})
s = [ "digraph \"process wfid #{wfid}\" {" ]
@expressions.each { |e| s.push(*e.send(:to_dot, opts)) }
@errors.each { |e| s.push(*e.send(:to_dot, opts)) }
s << '}'
s.join("\n")
end | [
"def",
"to_dot",
"(",
"opts",
"=",
"{",
"}",
")",
"s",
"=",
"[",
"\"digraph \\\"process wfid #{wfid}\\\" {\"",
"]",
"@expressions",
".",
"each",
"{",
"|",
"e",
"|",
"s",
".",
"push",
"(",
"*",
"e",
".",
"send",
"(",
":to_dot",
",",
"opts",
")",
")",
"}",
"@errors",
".",
"each",
"{",
"|",
"e",
"|",
"s",
".",
"push",
"(",
"*",
"e",
".",
"send",
"(",
":to_dot",
",",
"opts",
")",
")",
"}",
"s",
"<<",
"'}'",
"s",
".",
"join",
"(",
"\"\\n\"",
")",
"end"
]
| Returns a 'dot' representation of the process. A graph describing
the tree of flow expressions that compose the process. | [
"Returns",
"a",
"dot",
"representation",
"of",
"the",
"process",
".",
"A",
"graph",
"describing",
"the",
"tree",
"of",
"flow",
"expressions",
"that",
"compose",
"the",
"process",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/dboard/process_status.rb#L477-L485 | train |
jmettraux/ruote | lib/ruote/part/template.rb | Ruote.TemplateMixin.render_template | def render_template(template, flow_expression, workitem)
template = (File.read(template) rescue nil) if is_a_file?(template)
return render_default_template(workitem) unless template
template = template.to_s
workitem = workitem.to_h if workitem.respond_to?(:to_h)
@context.dollar_sub.s(template, flow_expression, workitem)
end | ruby | def render_template(template, flow_expression, workitem)
template = (File.read(template) rescue nil) if is_a_file?(template)
return render_default_template(workitem) unless template
template = template.to_s
workitem = workitem.to_h if workitem.respond_to?(:to_h)
@context.dollar_sub.s(template, flow_expression, workitem)
end | [
"def",
"render_template",
"(",
"template",
",",
"flow_expression",
",",
"workitem",
")",
"template",
"=",
"(",
"File",
".",
"read",
"(",
"template",
")",
"rescue",
"nil",
")",
"if",
"is_a_file?",
"(",
"template",
")",
"return",
"render_default_template",
"(",
"workitem",
")",
"unless",
"template",
"template",
"=",
"template",
".",
"to_s",
"workitem",
"=",
"workitem",
".",
"to_h",
"if",
"workitem",
".",
"respond_to?",
"(",
":to_h",
")",
"@context",
".",
"dollar_sub",
".",
"s",
"(",
"template",
",",
"flow_expression",
",",
"workitem",
")",
"end"
]
| Do the rendering. | [
"Do",
"the",
"rendering",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/part/template.rb#L44-L54 | train |
jmettraux/ruote | lib/ruote/part/template.rb | Ruote.TemplateMixin.render_default_template | def render_default_template(workitem)
workitem = workitem.to_h if workitem.respond_to?(:to_h)
s = []
s << "workitem for #{workitem['participant_name']}"
s << ''
s << Rufus::Json.pretty_encode(workitem['fei'])
s << ''
workitem['fields'].keys.sort.each do |key|
s << " - '#{key}' ==> #{Rufus::Json.encode(workitem['fields'][key])}"
end
s.join("\n")
end | ruby | def render_default_template(workitem)
workitem = workitem.to_h if workitem.respond_to?(:to_h)
s = []
s << "workitem for #{workitem['participant_name']}"
s << ''
s << Rufus::Json.pretty_encode(workitem['fei'])
s << ''
workitem['fields'].keys.sort.each do |key|
s << " - '#{key}' ==> #{Rufus::Json.encode(workitem['fields'][key])}"
end
s.join("\n")
end | [
"def",
"render_default_template",
"(",
"workitem",
")",
"workitem",
"=",
"workitem",
".",
"to_h",
"if",
"workitem",
".",
"respond_to?",
"(",
":to_h",
")",
"s",
"=",
"[",
"]",
"s",
"<<",
"\"workitem for #{workitem['participant_name']}\"",
"s",
"<<",
"''",
"s",
"<<",
"Rufus",
"::",
"Json",
".",
"pretty_encode",
"(",
"workitem",
"[",
"'fei'",
"]",
")",
"s",
"<<",
"''",
"workitem",
"[",
"'fields'",
"]",
".",
"keys",
".",
"sort",
".",
"each",
"do",
"|",
"key",
"|",
"s",
"<<",
"\" - '#{key}' ==> #{Rufus::Json.encode(workitem['fields'][key])}\"",
"end",
"s",
".",
"join",
"(",
"\"\\n\"",
")",
"end"
]
| Simply returns a pretty-printed view of the workitem | [
"Simply",
"returns",
"a",
"pretty",
"-",
"printed",
"view",
"of",
"the",
"workitem"
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/part/template.rb#L58-L71 | train |
jmettraux/ruote | lib/ruote/exp/fe_participant.rb | Ruote::Exp.ParticipantExpression.consider_participant_timers | def consider_participant_timers(p_info)
return if h.has_timers
# process definition takes precedence over participant defined timers.
timers = nil
[ :rtimers, :timers, :rtimeout ].each do |meth|
pa = @context.plist.instantiate(p_info, :if_respond_to? => meth)
next unless pa
timers = Ruote.participant_send(
pa, meth, 'workitem' => Ruote::Workitem.new(h.applied_workitem))
break if timers
end
return unless timers
timers = if timers.index(':')
timers.split(/,/)
else
[ "#{timers}: timeout" ]
end
schedule_timers(timers)
end | ruby | def consider_participant_timers(p_info)
return if h.has_timers
# process definition takes precedence over participant defined timers.
timers = nil
[ :rtimers, :timers, :rtimeout ].each do |meth|
pa = @context.plist.instantiate(p_info, :if_respond_to? => meth)
next unless pa
timers = Ruote.participant_send(
pa, meth, 'workitem' => Ruote::Workitem.new(h.applied_workitem))
break if timers
end
return unless timers
timers = if timers.index(':')
timers.split(/,/)
else
[ "#{timers}: timeout" ]
end
schedule_timers(timers)
end | [
"def",
"consider_participant_timers",
"(",
"p_info",
")",
"return",
"if",
"h",
".",
"has_timers",
"timers",
"=",
"nil",
"[",
":rtimers",
",",
":timers",
",",
":rtimeout",
"]",
".",
"each",
"do",
"|",
"meth",
"|",
"pa",
"=",
"@context",
".",
"plist",
".",
"instantiate",
"(",
"p_info",
",",
":if_respond_to?",
"=>",
"meth",
")",
"next",
"unless",
"pa",
"timers",
"=",
"Ruote",
".",
"participant_send",
"(",
"pa",
",",
"meth",
",",
"'workitem'",
"=>",
"Ruote",
"::",
"Workitem",
".",
"new",
"(",
"h",
".",
"applied_workitem",
")",
")",
"break",
"if",
"timers",
"end",
"return",
"unless",
"timers",
"timers",
"=",
"if",
"timers",
".",
"index",
"(",
"':'",
")",
"timers",
".",
"split",
"(",
"/",
"/",
")",
"else",
"[",
"\"#{timers}: timeout\"",
"]",
"end",
"schedule_timers",
"(",
"timers",
")",
"end"
]
| Determines and schedules timeout if any.
Note that process definition timeout has priority over participant
specified timeout. | [
"Determines",
"and",
"schedules",
"timeout",
"if",
"any",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/exp/fe_participant.rb#L279-L307 | train |
jmettraux/ruote | lib/ruote/part/local_participant.rb | Ruote.LocalParticipant.re_dispatch | def re_dispatch(wi=nil, opts=nil)
wi, opts = [ nil, wi ] if wi.is_a?(Hash) && opts.nil?
wi ||= workitem()
opts ||= {}
wi.h.re_dispatch_count = wi.h.re_dispatch_count.to_s.to_i + 1
msg = {
'action' => 'dispatch',
'fei' => wi.h.fei,
'workitem' => wi.to_h,
'participant_name' => wi.participant_name
}
if t = opts[:in] || opts[:at]
sched_id = @context.storage.put_schedule('at', wi.h.fei, t, msg)
exp = fexp(wi)
exp.h['re_dispatch_sched_id'] = sched_id
exp.try_persist
else
@context.storage.put_msg('dispatch', msg)
end
end | ruby | def re_dispatch(wi=nil, opts=nil)
wi, opts = [ nil, wi ] if wi.is_a?(Hash) && opts.nil?
wi ||= workitem()
opts ||= {}
wi.h.re_dispatch_count = wi.h.re_dispatch_count.to_s.to_i + 1
msg = {
'action' => 'dispatch',
'fei' => wi.h.fei,
'workitem' => wi.to_h,
'participant_name' => wi.participant_name
}
if t = opts[:in] || opts[:at]
sched_id = @context.storage.put_schedule('at', wi.h.fei, t, msg)
exp = fexp(wi)
exp.h['re_dispatch_sched_id'] = sched_id
exp.try_persist
else
@context.storage.put_msg('dispatch', msg)
end
end | [
"def",
"re_dispatch",
"(",
"wi",
"=",
"nil",
",",
"opts",
"=",
"nil",
")",
"wi",
",",
"opts",
"=",
"[",
"nil",
",",
"wi",
"]",
"if",
"wi",
".",
"is_a?",
"(",
"Hash",
")",
"&&",
"opts",
".",
"nil?",
"wi",
"||=",
"workitem",
"(",
")",
"opts",
"||=",
"{",
"}",
"wi",
".",
"h",
".",
"re_dispatch_count",
"=",
"wi",
".",
"h",
".",
"re_dispatch_count",
".",
"to_s",
".",
"to_i",
"+",
"1",
"msg",
"=",
"{",
"'action'",
"=>",
"'dispatch'",
",",
"'fei'",
"=>",
"wi",
".",
"h",
".",
"fei",
",",
"'workitem'",
"=>",
"wi",
".",
"to_h",
",",
"'participant_name'",
"=>",
"wi",
".",
"participant_name",
"}",
"if",
"t",
"=",
"opts",
"[",
":in",
"]",
"||",
"opts",
"[",
":at",
"]",
"sched_id",
"=",
"@context",
".",
"storage",
".",
"put_schedule",
"(",
"'at'",
",",
"wi",
".",
"h",
".",
"fei",
",",
"t",
",",
"msg",
")",
"exp",
"=",
"fexp",
"(",
"wi",
")",
"exp",
".",
"h",
"[",
"'re_dispatch_sched_id'",
"]",
"=",
"sched_id",
"exp",
".",
"try_persist",
"else",
"@context",
".",
"storage",
".",
"put_msg",
"(",
"'dispatch'",
",",
"msg",
")",
"end",
"end"
]
| Use this method to re_dispatch the workitem.
It takes two options :in and :at for "later re_dispatch".
Look at the unschedule_re_dispatch method for an example of
participant implementation that uses re_dispatch.
Without one of those options, the method is a "reject". | [
"Use",
"this",
"method",
"to",
"re_dispatch",
"the",
"workitem",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/part/local_participant.rb#L156-L183 | train |
jmettraux/ruote | lib/ruote/svc/error_handler.rb | Ruote.ErrorHandler.msg_handle | def msg_handle(msg, err)
fexp = Ruote::Exp::FlowExpression.fetch(
@context, msg['fei'] || msg['workitem']['fei']
) rescue nil
handle(msg, fexp, err)
end | ruby | def msg_handle(msg, err)
fexp = Ruote::Exp::FlowExpression.fetch(
@context, msg['fei'] || msg['workitem']['fei']
) rescue nil
handle(msg, fexp, err)
end | [
"def",
"msg_handle",
"(",
"msg",
",",
"err",
")",
"fexp",
"=",
"Ruote",
"::",
"Exp",
"::",
"FlowExpression",
".",
"fetch",
"(",
"@context",
",",
"msg",
"[",
"'fei'",
"]",
"||",
"msg",
"[",
"'workitem'",
"]",
"[",
"'fei'",
"]",
")",
"rescue",
"nil",
"handle",
"(",
"msg",
",",
"fexp",
",",
"err",
")",
"end"
]
| As used by the dispatch pool and the worker. | [
"As",
"used",
"by",
"the",
"dispatch",
"pool",
"and",
"the",
"worker",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/svc/error_handler.rb#L59-L66 | train |
jmettraux/ruote | lib/ruote/svc/error_handler.rb | Ruote.ErrorHandler.msg_raise | def msg_raise(msg, err)
fei = msg['fei']
wfid = msg['wfid'] || msg.fetch('fei', {})['wfid']
@context.storage.put_msg(
'raise',
'fei' => fei,
'wfid' => wfid,
'msg' => msg,
'error' => deflate(err, fei))
end | ruby | def msg_raise(msg, err)
fei = msg['fei']
wfid = msg['wfid'] || msg.fetch('fei', {})['wfid']
@context.storage.put_msg(
'raise',
'fei' => fei,
'wfid' => wfid,
'msg' => msg,
'error' => deflate(err, fei))
end | [
"def",
"msg_raise",
"(",
"msg",
",",
"err",
")",
"fei",
"=",
"msg",
"[",
"'fei'",
"]",
"wfid",
"=",
"msg",
"[",
"'wfid'",
"]",
"||",
"msg",
".",
"fetch",
"(",
"'fei'",
",",
"{",
"}",
")",
"[",
"'wfid'",
"]",
"@context",
".",
"storage",
".",
"put_msg",
"(",
"'raise'",
",",
"'fei'",
"=>",
"fei",
",",
"'wfid'",
"=>",
"wfid",
",",
"'msg'",
"=>",
"msg",
",",
"'error'",
"=>",
"deflate",
"(",
"err",
",",
"fei",
")",
")",
"end"
]
| Packages the error in a 'raise' msg and places it in the storage,
for a worker to pick it up.
TODO: investigate: is it still used, relevant? (probably yes, ruote-swf) | [
"Packages",
"the",
"error",
"in",
"a",
"raise",
"msg",
"and",
"places",
"it",
"in",
"the",
"storage",
"for",
"a",
"worker",
"to",
"pick",
"it",
"up",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/svc/error_handler.rb#L73-L84 | train |
jmettraux/ruote | lib/ruote/svc/error_handler.rb | Ruote.ErrorHandler.handle | def handle(msg, fexp, err)
err = RaisedError.new(err) unless err.respond_to?(:backtrace)
meta = err.is_a?(Ruote::MetaError)
fei = msg['fei'] || (fexp.h.fei rescue nil)
wfid = msg['wfid'] || (fei || {})['wfid']
# on_error ?
return if ( ! meta) && fexp && fexp.handle_on_error(msg, err)
# emit 'msg'
#
# (this message might get intercepted by a tracker)
herr = deflate(err, fei, fexp)
# fill error in the error journal
@context.storage.put(
herr.merge(
'type' => 'errors',
'_id' => "err_#{Ruote.to_storage_id(fei)}",
'message' => err.inspect, # :-(
'trace' => (err.backtrace || []).join("\n"), # :-(
'msg' => msg)
) if fei
# advertise 'error_intercepted'
@context.storage.put_msg(
'error_intercepted',
'error' => herr, 'wfid' => wfid, 'fei' => fei, 'msg' => msg)
rescue => e
raise e unless @context.worker
@context.worker.send(
:handle_step_error,
e,
{ 'action' => 'error_intercepted',
'error' => deflate(err, fei),
'fei' => fei,
'wfid' => wfid,
'msg' => msg })
end | ruby | def handle(msg, fexp, err)
err = RaisedError.new(err) unless err.respond_to?(:backtrace)
meta = err.is_a?(Ruote::MetaError)
fei = msg['fei'] || (fexp.h.fei rescue nil)
wfid = msg['wfid'] || (fei || {})['wfid']
# on_error ?
return if ( ! meta) && fexp && fexp.handle_on_error(msg, err)
# emit 'msg'
#
# (this message might get intercepted by a tracker)
herr = deflate(err, fei, fexp)
# fill error in the error journal
@context.storage.put(
herr.merge(
'type' => 'errors',
'_id' => "err_#{Ruote.to_storage_id(fei)}",
'message' => err.inspect, # :-(
'trace' => (err.backtrace || []).join("\n"), # :-(
'msg' => msg)
) if fei
# advertise 'error_intercepted'
@context.storage.put_msg(
'error_intercepted',
'error' => herr, 'wfid' => wfid, 'fei' => fei, 'msg' => msg)
rescue => e
raise e unless @context.worker
@context.worker.send(
:handle_step_error,
e,
{ 'action' => 'error_intercepted',
'error' => deflate(err, fei),
'fei' => fei,
'wfid' => wfid,
'msg' => msg })
end | [
"def",
"handle",
"(",
"msg",
",",
"fexp",
",",
"err",
")",
"err",
"=",
"RaisedError",
".",
"new",
"(",
"err",
")",
"unless",
"err",
".",
"respond_to?",
"(",
":backtrace",
")",
"meta",
"=",
"err",
".",
"is_a?",
"(",
"Ruote",
"::",
"MetaError",
")",
"fei",
"=",
"msg",
"[",
"'fei'",
"]",
"||",
"(",
"fexp",
".",
"h",
".",
"fei",
"rescue",
"nil",
")",
"wfid",
"=",
"msg",
"[",
"'wfid'",
"]",
"||",
"(",
"fei",
"||",
"{",
"}",
")",
"[",
"'wfid'",
"]",
"return",
"if",
"(",
"!",
"meta",
")",
"&&",
"fexp",
"&&",
"fexp",
".",
"handle_on_error",
"(",
"msg",
",",
"err",
")",
"herr",
"=",
"deflate",
"(",
"err",
",",
"fei",
",",
"fexp",
")",
"@context",
".",
"storage",
".",
"put",
"(",
"herr",
".",
"merge",
"(",
"'type'",
"=>",
"'errors'",
",",
"'_id'",
"=>",
"\"err_#{Ruote.to_storage_id(fei)}\"",
",",
"'message'",
"=>",
"err",
".",
"inspect",
",",
"'trace'",
"=>",
"(",
"err",
".",
"backtrace",
"||",
"[",
"]",
")",
".",
"join",
"(",
"\"\\n\"",
")",
",",
"'msg'",
"=>",
"msg",
")",
")",
"if",
"fei",
"@context",
".",
"storage",
".",
"put_msg",
"(",
"'error_intercepted'",
",",
"'error'",
"=>",
"herr",
",",
"'wfid'",
"=>",
"wfid",
",",
"'fei'",
"=>",
"fei",
",",
"'msg'",
"=>",
"msg",
")",
"rescue",
"=>",
"e",
"raise",
"e",
"unless",
"@context",
".",
"worker",
"@context",
".",
"worker",
".",
"send",
"(",
":handle_step_error",
",",
"e",
",",
"{",
"'action'",
"=>",
"'error_intercepted'",
",",
"'error'",
"=>",
"deflate",
"(",
"err",
",",
"fei",
")",
",",
"'fei'",
"=>",
"fei",
",",
"'wfid'",
"=>",
"wfid",
",",
"'msg'",
"=>",
"msg",
"}",
")",
"end"
]
| Called by msg_handle or action_handle. | [
"Called",
"by",
"msg_handle",
"or",
"action_handle",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/svc/error_handler.rb#L108-L156 | train |
jmettraux/ruote | lib/ruote/svc/error_handler.rb | Ruote.ErrorHandler.deflate | def deflate(err, fei, fexp=nil)
return err unless err.respond_to?(:backtrace)
fexp ||=
Ruote::Exp::FlowExpression.dummy('fei' => fei, 'original_tree' => nil)
fexp.deflate(err)
end | ruby | def deflate(err, fei, fexp=nil)
return err unless err.respond_to?(:backtrace)
fexp ||=
Ruote::Exp::FlowExpression.dummy('fei' => fei, 'original_tree' => nil)
fexp.deflate(err)
end | [
"def",
"deflate",
"(",
"err",
",",
"fei",
",",
"fexp",
"=",
"nil",
")",
"return",
"err",
"unless",
"err",
".",
"respond_to?",
"(",
":backtrace",
")",
"fexp",
"||=",
"Ruote",
"::",
"Exp",
"::",
"FlowExpression",
".",
"dummy",
"(",
"'fei'",
"=>",
"fei",
",",
"'original_tree'",
"=>",
"nil",
")",
"fexp",
".",
"deflate",
"(",
"err",
")",
"end"
]
| Returns a serializable hash with all the details of the error. | [
"Returns",
"a",
"serializable",
"hash",
"with",
"all",
"the",
"details",
"of",
"the",
"error",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/svc/error_handler.rb#L160-L168 | train |
jmettraux/ruote | lib/ruote/exp/fe_concurrence.rb | Ruote::Exp.ConcurrenceExpression.expected_count | def expected_count
if h.ccount.nil?
count_list_size
elsif h.ccount >= 0
[ h.ccount, count_list_size ].min
else # all but 1, 2, ...
i = count_list_size + h.ccount
i < 1 ? 1 : i
end
end | ruby | def expected_count
if h.ccount.nil?
count_list_size
elsif h.ccount >= 0
[ h.ccount, count_list_size ].min
else # all but 1, 2, ...
i = count_list_size + h.ccount
i < 1 ? 1 : i
end
end | [
"def",
"expected_count",
"if",
"h",
".",
"ccount",
".",
"nil?",
"count_list_size",
"elsif",
"h",
".",
"ccount",
">=",
"0",
"[",
"h",
".",
"ccount",
",",
"count_list_size",
"]",
".",
"min",
"else",
"i",
"=",
"count_list_size",
"+",
"h",
".",
"ccount",
"i",
"<",
"1",
"?",
"1",
":",
"i",
"end",
"end"
]
| How many branch replies are expected before the concurrence is over ? | [
"How",
"many",
"branch",
"replies",
"are",
"expected",
"before",
"the",
"concurrence",
"is",
"over",
"?"
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/exp/fe_concurrence.rb#L449-L459 | train |
jmettraux/ruote | lib/ruote/exp/fe_concurrence.rb | Ruote::Exp.ConcurrenceExpression.merge_workitems | def merge_workitems(workitems, merge_type)
workitems.inject(nil) do |t, wi|
Ruote.merge_workitem(workitem_index(wi), t, wi, merge_type)
end
end | ruby | def merge_workitems(workitems, merge_type)
workitems.inject(nil) do |t, wi|
Ruote.merge_workitem(workitem_index(wi), t, wi, merge_type)
end
end | [
"def",
"merge_workitems",
"(",
"workitems",
",",
"merge_type",
")",
"workitems",
".",
"inject",
"(",
"nil",
")",
"do",
"|",
"t",
",",
"wi",
"|",
"Ruote",
".",
"merge_workitem",
"(",
"workitem_index",
"(",
"wi",
")",
",",
"t",
",",
"wi",
",",
"merge_type",
")",
"end",
"end"
]
| Given a list of workitems and a merge_type, will merge according to
the merge type.
The return value is the merged workitem.
(Still used when dealing with highest/lowest merge_type and legacy
concurrence/citerator expressions) | [
"Given",
"a",
"list",
"of",
"workitems",
"and",
"a",
"merge_type",
"will",
"merge",
"according",
"to",
"the",
"merge",
"type",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/exp/fe_concurrence.rb#L593-L598 | train |
jmettraux/ruote | lib/ruote/workitem.rb | Ruote.Workitem.as_json | def as_json(pretty=false)
pretty ? Rufus::Json.pretty_encode(@h) : Rufus::Json.encode(@h)
end | ruby | def as_json(pretty=false)
pretty ? Rufus::Json.pretty_encode(@h) : Rufus::Json.encode(@h)
end | [
"def",
"as_json",
"(",
"pretty",
"=",
"false",
")",
"pretty",
"?",
"Rufus",
"::",
"Json",
".",
"pretty_encode",
"(",
"@h",
")",
":",
"Rufus",
"::",
"Json",
".",
"encode",
"(",
"@h",
")",
"end"
]
| Encodes this workitem as JSON. If pretty is set to true, will output
prettified JSON. | [
"Encodes",
"this",
"workitem",
"as",
"JSON",
".",
"If",
"pretty",
"is",
"set",
"to",
"true",
"will",
"output",
"prettified",
"JSON",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/workitem.rb#L385-L388 | train |
jmettraux/ruote | lib/ruote/workitem.rb | Ruote.Workitem.remove_tag | def remove_tag(tag)
# it's a bit convoluted... trying to cope with potential inconsistencies
#
# normally, it should only be a tags.pop(), but since user have
# access to the workitem and its fields... better be safe than sorry
tags = (h.fields['__tags__'] || [])
if index = tags.rindex(tag)
tags.delete_at(index)
end
h.fields['__left_tag__'] = tag
end | ruby | def remove_tag(tag)
# it's a bit convoluted... trying to cope with potential inconsistencies
#
# normally, it should only be a tags.pop(), but since user have
# access to the workitem and its fields... better be safe than sorry
tags = (h.fields['__tags__'] || [])
if index = tags.rindex(tag)
tags.delete_at(index)
end
h.fields['__left_tag__'] = tag
end | [
"def",
"remove_tag",
"(",
"tag",
")",
"tags",
"=",
"(",
"h",
".",
"fields",
"[",
"'__tags__'",
"]",
"||",
"[",
"]",
")",
"if",
"index",
"=",
"tags",
".",
"rindex",
"(",
"tag",
")",
"tags",
".",
"delete_at",
"(",
"index",
")",
"end",
"h",
".",
"fields",
"[",
"'__left_tag__'",
"]",
"=",
"tag",
"end"
]
| Used by FlowExpression when leaving a tag. | [
"Used",
"by",
"FlowExpression",
"when",
"leaving",
"a",
"tag",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/workitem.rb#L415-L429 | train |
jmettraux/ruote | lib/ruote/svc/dispatch_pool.rb | Ruote.DispatchPool.dispatch | def dispatch(msg)
participant = @context.plist.lookup(
msg['participant'] || msg['participant_name'], msg['workitem'])
if
@context['participant_threads_enabled'] == false ||
do_not_thread?(participant, msg)
then
do_dispatch(participant, msg)
else
do_threaded_dispatch(participant, msg)
end
end | ruby | def dispatch(msg)
participant = @context.plist.lookup(
msg['participant'] || msg['participant_name'], msg['workitem'])
if
@context['participant_threads_enabled'] == false ||
do_not_thread?(participant, msg)
then
do_dispatch(participant, msg)
else
do_threaded_dispatch(participant, msg)
end
end | [
"def",
"dispatch",
"(",
"msg",
")",
"participant",
"=",
"@context",
".",
"plist",
".",
"lookup",
"(",
"msg",
"[",
"'participant'",
"]",
"||",
"msg",
"[",
"'participant_name'",
"]",
",",
"msg",
"[",
"'workitem'",
"]",
")",
"if",
"@context",
"[",
"'participant_threads_enabled'",
"]",
"==",
"false",
"||",
"do_not_thread?",
"(",
"participant",
",",
"msg",
")",
"then",
"do_dispatch",
"(",
"participant",
",",
"msg",
")",
"else",
"do_threaded_dispatch",
"(",
"participant",
",",
"msg",
")",
"end",
"end"
]
| Dispatching the msg. | [
"Dispatching",
"the",
"msg",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/svc/dispatch_pool.rb#L53-L66 | train |
jmettraux/ruote | lib/ruote/svc/dispatch_pool.rb | Ruote.DispatchPool.do_dispatch | def do_dispatch(participant, msg)
do_raw_dispatch(participant, msg)
rescue => err
@context.error_handler.msg_handle(msg, err)
end | ruby | def do_dispatch(participant, msg)
do_raw_dispatch(participant, msg)
rescue => err
@context.error_handler.msg_handle(msg, err)
end | [
"def",
"do_dispatch",
"(",
"participant",
",",
"msg",
")",
"do_raw_dispatch",
"(",
"participant",
",",
"msg",
")",
"rescue",
"=>",
"err",
"@context",
".",
"error_handler",
".",
"msg_handle",
"(",
"msg",
",",
"err",
")",
"end"
]
| The raw dispatch work, wrapped in error handling. | [
"The",
"raw",
"dispatch",
"work",
"wrapped",
"in",
"error",
"handling",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/svc/dispatch_pool.rb#L93-L99 | train |
jmettraux/ruote | lib/ruote/svc/dispatch_pool.rb | Ruote.DispatchPool.do_threaded_dispatch | def do_threaded_dispatch(participant, msg)
msg = Rufus::Json.dup(msg)
#
# the thread gets its own copy of the message
# (especially important if the main thread does something with
# the message 'during' the dispatch)
# Maybe at some point a limit on the number of dispatch threads
# would be OK.
# Or maybe it's the job of an extension / subclass
Thread.new { do_dispatch(participant, msg) }
end | ruby | def do_threaded_dispatch(participant, msg)
msg = Rufus::Json.dup(msg)
#
# the thread gets its own copy of the message
# (especially important if the main thread does something with
# the message 'during' the dispatch)
# Maybe at some point a limit on the number of dispatch threads
# would be OK.
# Or maybe it's the job of an extension / subclass
Thread.new { do_dispatch(participant, msg) }
end | [
"def",
"do_threaded_dispatch",
"(",
"participant",
",",
"msg",
")",
"msg",
"=",
"Rufus",
"::",
"Json",
".",
"dup",
"(",
"msg",
")",
"Thread",
".",
"new",
"{",
"do_dispatch",
"(",
"participant",
",",
"msg",
")",
"}",
"end"
]
| Wraps the call to do_dispatch in a thread. | [
"Wraps",
"the",
"call",
"to",
"do_dispatch",
"in",
"a",
"thread",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/svc/dispatch_pool.rb#L103-L116 | train |
jmettraux/ruote | lib/ruote/svc/dispatch_pool.rb | Ruote.DispatchPool.dispatch_cancel | def dispatch_cancel(msg)
flavour = msg['flavour']
participant = @context.plist.instantiate(msg['participant'])
result = begin
Ruote.participant_send(
participant,
[ :on_cancel, :cancel ],
'fei' => Ruote::FlowExpressionId.new(msg['fei']),
'flavour' => flavour)
rescue => e
raise(e) if flavour != 'kill'
end
@context.storage.put_msg(
'reply',
'fei' => msg['fei'],
'workitem' => msg['workitem']
) if result != false
end | ruby | def dispatch_cancel(msg)
flavour = msg['flavour']
participant = @context.plist.instantiate(msg['participant'])
result = begin
Ruote.participant_send(
participant,
[ :on_cancel, :cancel ],
'fei' => Ruote::FlowExpressionId.new(msg['fei']),
'flavour' => flavour)
rescue => e
raise(e) if flavour != 'kill'
end
@context.storage.put_msg(
'reply',
'fei' => msg['fei'],
'workitem' => msg['workitem']
) if result != false
end | [
"def",
"dispatch_cancel",
"(",
"msg",
")",
"flavour",
"=",
"msg",
"[",
"'flavour'",
"]",
"participant",
"=",
"@context",
".",
"plist",
".",
"instantiate",
"(",
"msg",
"[",
"'participant'",
"]",
")",
"result",
"=",
"begin",
"Ruote",
".",
"participant_send",
"(",
"participant",
",",
"[",
":on_cancel",
",",
":cancel",
"]",
",",
"'fei'",
"=>",
"Ruote",
"::",
"FlowExpressionId",
".",
"new",
"(",
"msg",
"[",
"'fei'",
"]",
")",
",",
"'flavour'",
"=>",
"flavour",
")",
"rescue",
"=>",
"e",
"raise",
"(",
"e",
")",
"if",
"flavour",
"!=",
"'kill'",
"end",
"@context",
".",
"storage",
".",
"put_msg",
"(",
"'reply'",
",",
"'fei'",
"=>",
"msg",
"[",
"'fei'",
"]",
",",
"'workitem'",
"=>",
"msg",
"[",
"'workitem'",
"]",
")",
"if",
"result",
"!=",
"false",
"end"
]
| Instantiates the participant and calls its cancel method. | [
"Instantiates",
"the",
"participant",
"and",
"calls",
"its",
"cancel",
"method",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/svc/dispatch_pool.rb#L134-L157 | train |
jmettraux/ruote | lib/ruote/receiver/base.rb | Ruote.ReceiverMixin.receive | def receive(workitem)
workitem = workitem.to_h if workitem.respond_to?(:to_h)
@context.storage.put_msg(
'receive',
'fei' => workitem['fei'],
'workitem' => workitem,
'participant_name' => workitem['participant_name'],
'receiver' => sign)
end | ruby | def receive(workitem)
workitem = workitem.to_h if workitem.respond_to?(:to_h)
@context.storage.put_msg(
'receive',
'fei' => workitem['fei'],
'workitem' => workitem,
'participant_name' => workitem['participant_name'],
'receiver' => sign)
end | [
"def",
"receive",
"(",
"workitem",
")",
"workitem",
"=",
"workitem",
".",
"to_h",
"if",
"workitem",
".",
"respond_to?",
"(",
":to_h",
")",
"@context",
".",
"storage",
".",
"put_msg",
"(",
"'receive'",
",",
"'fei'",
"=>",
"workitem",
"[",
"'fei'",
"]",
",",
"'workitem'",
"=>",
"workitem",
",",
"'participant_name'",
"=>",
"workitem",
"[",
"'participant_name'",
"]",
",",
"'receiver'",
"=>",
"sign",
")",
"end"
]
| This method pipes back a workitem into the engine, letting it resume
in its flow, hopefully. | [
"This",
"method",
"pipes",
"back",
"a",
"workitem",
"into",
"the",
"engine",
"letting",
"it",
"resume",
"in",
"its",
"flow",
"hopefully",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/receiver/base.rb#L75-L85 | train |
jmettraux/ruote | lib/ruote/receiver/base.rb | Ruote.ReceiverMixin.flunk | def flunk(workitem, error_class_or_instance_or_message, *err_arguments)
err = error_class_or_instance_or_message
trace = Ruote.pop_trace(err_arguments)
err =
case err
when Exception
err
when Class
err.new(*err_arguments)
when String
begin
Ruote.constantize(err).new(*err_arguments)
rescue #NameError # rescue instanciation errors too
RuntimeError.new(err)
end
else
ArgumentError.new(
"flunk() failed, cannot bring back err from #{err.inspect}")
end
err.set_backtrace(trace || err.backtrace || caller)
workitem = workitem.to_h if workitem.respond_to?(:to_h)
at = Ruote.now_to_utc_s
@context.storage.put_msg(
'raise',
'fei' => workitem['fei'],
'wfid' => workitem['wfid'],
'msg' => {
'action' => 'dispatch',
'fei' => workitem['fei'],
'participant_name' => workitem['participant_name'],
'participant' => nil,
'workitem' => workitem,
'put_at' => at
},
'error' => {
'class' => err.class.name,
'message' => err.message,
'trace' => err.backtrace,
'at' => at,
'details' => err.respond_to?(:ruote_details) ? err.ruote_details : nil
})
end | ruby | def flunk(workitem, error_class_or_instance_or_message, *err_arguments)
err = error_class_or_instance_or_message
trace = Ruote.pop_trace(err_arguments)
err =
case err
when Exception
err
when Class
err.new(*err_arguments)
when String
begin
Ruote.constantize(err).new(*err_arguments)
rescue #NameError # rescue instanciation errors too
RuntimeError.new(err)
end
else
ArgumentError.new(
"flunk() failed, cannot bring back err from #{err.inspect}")
end
err.set_backtrace(trace || err.backtrace || caller)
workitem = workitem.to_h if workitem.respond_to?(:to_h)
at = Ruote.now_to_utc_s
@context.storage.put_msg(
'raise',
'fei' => workitem['fei'],
'wfid' => workitem['wfid'],
'msg' => {
'action' => 'dispatch',
'fei' => workitem['fei'],
'participant_name' => workitem['participant_name'],
'participant' => nil,
'workitem' => workitem,
'put_at' => at
},
'error' => {
'class' => err.class.name,
'message' => err.message,
'trace' => err.backtrace,
'at' => at,
'details' => err.respond_to?(:ruote_details) ? err.ruote_details : nil
})
end | [
"def",
"flunk",
"(",
"workitem",
",",
"error_class_or_instance_or_message",
",",
"*",
"err_arguments",
")",
"err",
"=",
"error_class_or_instance_or_message",
"trace",
"=",
"Ruote",
".",
"pop_trace",
"(",
"err_arguments",
")",
"err",
"=",
"case",
"err",
"when",
"Exception",
"err",
"when",
"Class",
"err",
".",
"new",
"(",
"*",
"err_arguments",
")",
"when",
"String",
"begin",
"Ruote",
".",
"constantize",
"(",
"err",
")",
".",
"new",
"(",
"*",
"err_arguments",
")",
"rescue",
"RuntimeError",
".",
"new",
"(",
"err",
")",
"end",
"else",
"ArgumentError",
".",
"new",
"(",
"\"flunk() failed, cannot bring back err from #{err.inspect}\"",
")",
"end",
"err",
".",
"set_backtrace",
"(",
"trace",
"||",
"err",
".",
"backtrace",
"||",
"caller",
")",
"workitem",
"=",
"workitem",
".",
"to_h",
"if",
"workitem",
".",
"respond_to?",
"(",
":to_h",
")",
"at",
"=",
"Ruote",
".",
"now_to_utc_s",
"@context",
".",
"storage",
".",
"put_msg",
"(",
"'raise'",
",",
"'fei'",
"=>",
"workitem",
"[",
"'fei'",
"]",
",",
"'wfid'",
"=>",
"workitem",
"[",
"'wfid'",
"]",
",",
"'msg'",
"=>",
"{",
"'action'",
"=>",
"'dispatch'",
",",
"'fei'",
"=>",
"workitem",
"[",
"'fei'",
"]",
",",
"'participant_name'",
"=>",
"workitem",
"[",
"'participant_name'",
"]",
",",
"'participant'",
"=>",
"nil",
",",
"'workitem'",
"=>",
"workitem",
",",
"'put_at'",
"=>",
"at",
"}",
",",
"'error'",
"=>",
"{",
"'class'",
"=>",
"err",
".",
"class",
".",
"name",
",",
"'message'",
"=>",
"err",
".",
"message",
",",
"'trace'",
"=>",
"err",
".",
"backtrace",
",",
"'at'",
"=>",
"at",
",",
"'details'",
"=>",
"err",
".",
"respond_to?",
"(",
":ruote_details",
")",
"?",
"err",
".",
"ruote_details",
":",
"nil",
"}",
")",
"end"
]
| Can be used to raise an error in the workflow instance.
Can be called either with an error class and arguments, either with
an error instance (and no arguments), or a string message and no
arguments.
The workitem can be either an instance of Ruote::Workitem or a workitem
in its Hash representation.
receiver.flunk(workitem, ArgumentError, "not enough info")
receiver.flunk(workitem, "ArgumentError", "not enough info")
receiver.flunk(workitem, ArgumentError, "not enough info", backtrace)
receiver.flunk(workitem, "ArgumentError", "not enough info", backtrace)
receiver.flunk(workitem, "not enough info")
rescue => e
receiver.flunk(workitem, e)
end | [
"Can",
"be",
"used",
"to",
"raise",
"an",
"error",
"in",
"the",
"workflow",
"instance",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/receiver/base.rb#L116-L163 | train |
jmettraux/ruote | lib/ruote/receiver/base.rb | Ruote.ReceiverMixin.launch | def launch(process_definition, fields={}, variables={}, root_stash=nil)
#puts caller.select { |l|
# ! (l.match(/test\/unit[\.\/]/) or l.match(/\/rspec-core-/))
#} if @context.logger.noisy
#
# this is useful when noisy and running through a set of tests
wfid = fields[:wfid] || @context.wfidgen.generate
fields = Rufus::Json.dup(fields)
variables = Rufus::Json.dup(variables)
root_stash = Rufus::Json.dup(root_stash)
#
# making sure symbols are turned to strings
@context.storage.put_msg(
'launch',
'wfid' => wfid,
'tree' => @context.reader.read(process_definition),
'workitem' => { 'fields' => fields },
'variables' => variables,
'stash' => root_stash)
wfid
end | ruby | def launch(process_definition, fields={}, variables={}, root_stash=nil)
#puts caller.select { |l|
# ! (l.match(/test\/unit[\.\/]/) or l.match(/\/rspec-core-/))
#} if @context.logger.noisy
#
# this is useful when noisy and running through a set of tests
wfid = fields[:wfid] || @context.wfidgen.generate
fields = Rufus::Json.dup(fields)
variables = Rufus::Json.dup(variables)
root_stash = Rufus::Json.dup(root_stash)
#
# making sure symbols are turned to strings
@context.storage.put_msg(
'launch',
'wfid' => wfid,
'tree' => @context.reader.read(process_definition),
'workitem' => { 'fields' => fields },
'variables' => variables,
'stash' => root_stash)
wfid
end | [
"def",
"launch",
"(",
"process_definition",
",",
"fields",
"=",
"{",
"}",
",",
"variables",
"=",
"{",
"}",
",",
"root_stash",
"=",
"nil",
")",
"wfid",
"=",
"fields",
"[",
":wfid",
"]",
"||",
"@context",
".",
"wfidgen",
".",
"generate",
"fields",
"=",
"Rufus",
"::",
"Json",
".",
"dup",
"(",
"fields",
")",
"variables",
"=",
"Rufus",
"::",
"Json",
".",
"dup",
"(",
"variables",
")",
"root_stash",
"=",
"Rufus",
"::",
"Json",
".",
"dup",
"(",
"root_stash",
")",
"@context",
".",
"storage",
".",
"put_msg",
"(",
"'launch'",
",",
"'wfid'",
"=>",
"wfid",
",",
"'tree'",
"=>",
"@context",
".",
"reader",
".",
"read",
"(",
"process_definition",
")",
",",
"'workitem'",
"=>",
"{",
"'fields'",
"=>",
"fields",
"}",
",",
"'variables'",
"=>",
"variables",
",",
"'stash'",
"=>",
"root_stash",
")",
"wfid",
"end"
]
| Given a process definitions and optional initial fields and variables,
launches a new process instance.
This method is mostly used from the Ruote::Dashboard class (which
includes this mixin).
process_definition must be a result of Ruote.process_definition call
or XML or JSON serialized process definition, as accepted by
Ruote::Reader#read.
fields are workflow parameters that will be placed in workitem.fields.
Calls to this method returns the newly launched "workflow instance id"
("wfid" for short), the [hopefully] unique identifier for the
process instance.
== custom :wfid
When calling this method, it's OK to pass a field named :wfid (Symbol,
not String) that will be used as the identifier for the process instance. | [
"Given",
"a",
"process",
"definitions",
"and",
"optional",
"initial",
"fields",
"and",
"variables",
"launches",
"a",
"new",
"process",
"instance",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/receiver/base.rb#L186-L211 | train |
jmettraux/ruote | lib/ruote/receiver/base.rb | Ruote.ReceiverMixin.fetch_flow_expression | def fetch_flow_expression(workitem_or_fei)
Ruote::Exp::FlowExpression.fetch(
@context,
Ruote::FlowExpressionId.extract_h(workitem_or_fei))
end | ruby | def fetch_flow_expression(workitem_or_fei)
Ruote::Exp::FlowExpression.fetch(
@context,
Ruote::FlowExpressionId.extract_h(workitem_or_fei))
end | [
"def",
"fetch_flow_expression",
"(",
"workitem_or_fei",
")",
"Ruote",
"::",
"Exp",
"::",
"FlowExpression",
".",
"fetch",
"(",
"@context",
",",
"Ruote",
"::",
"FlowExpressionId",
".",
"extract_h",
"(",
"workitem_or_fei",
")",
")",
"end"
]
| Convenience method, given a workitem or a fei, returns the
corresponding flow expession. | [
"Convenience",
"method",
"given",
"a",
"workitem",
"or",
"a",
"fei",
"returns",
"the",
"corresponding",
"flow",
"expession",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/receiver/base.rb#L225-L230 | train |
jmettraux/ruote | lib/ruote/receiver/base.rb | Ruote.ReceiverMixin.stash_get | def stash_get(workitem_or_fei, key=nil)
stash = fetch_flow_expression(workitem_or_fei).h['stash'] rescue nil
stash ||= {}
key ? stash[key] : stash
end | ruby | def stash_get(workitem_or_fei, key=nil)
stash = fetch_flow_expression(workitem_or_fei).h['stash'] rescue nil
stash ||= {}
key ? stash[key] : stash
end | [
"def",
"stash_get",
"(",
"workitem_or_fei",
",",
"key",
"=",
"nil",
")",
"stash",
"=",
"fetch_flow_expression",
"(",
"workitem_or_fei",
")",
".",
"h",
"[",
"'stash'",
"]",
"rescue",
"nil",
"stash",
"||=",
"{",
"}",
"key",
"?",
"stash",
"[",
"key",
"]",
":",
"stash",
"end"
]
| Fetches back a stashed value.
get(fei, 'colour')
# => 'blue'
To return the whole stash
get(fei)
# => { 'colour' => 'blue' }
put & get are useful for a participant that needs to communicate
between its consume and its cancel. | [
"Fetches",
"back",
"a",
"stashed",
"value",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/receiver/base.rb#L306-L312 | train |
jmettraux/ruote | lib/ruote/worker.rb | Ruote.Worker.inactive? | def inactive?
# the cheaper tests first
return false if @msgs.size > 0
return false unless @context.storage.empty?('schedules')
return false unless @context.storage.empty?('msgs')
wfids = @context.storage.get_many('expressions').collect { |exp|
exp['fei']['wfid']
}
error_wfids = @context.storage.get_many('errors').collect { |err|
err['fei']['wfid']
}
(wfids - error_wfids == [])
end | ruby | def inactive?
# the cheaper tests first
return false if @msgs.size > 0
return false unless @context.storage.empty?('schedules')
return false unless @context.storage.empty?('msgs')
wfids = @context.storage.get_many('expressions').collect { |exp|
exp['fei']['wfid']
}
error_wfids = @context.storage.get_many('errors').collect { |err|
err['fei']['wfid']
}
(wfids - error_wfids == [])
end | [
"def",
"inactive?",
"return",
"false",
"if",
"@msgs",
".",
"size",
">",
"0",
"return",
"false",
"unless",
"@context",
".",
"storage",
".",
"empty?",
"(",
"'schedules'",
")",
"return",
"false",
"unless",
"@context",
".",
"storage",
".",
"empty?",
"(",
"'msgs'",
")",
"wfids",
"=",
"@context",
".",
"storage",
".",
"get_many",
"(",
"'expressions'",
")",
".",
"collect",
"{",
"|",
"exp",
"|",
"exp",
"[",
"'fei'",
"]",
"[",
"'wfid'",
"]",
"}",
"error_wfids",
"=",
"@context",
".",
"storage",
".",
"get_many",
"(",
"'errors'",
")",
".",
"collect",
"{",
"|",
"err",
"|",
"err",
"[",
"'fei'",
"]",
"[",
"'wfid'",
"]",
"}",
"(",
"wfids",
"-",
"error_wfids",
"==",
"[",
"]",
")",
"end"
]
| Returns true if the engine system is inactive, ie if all the process
instances are terminated or are stuck in an error.
NOTE : for now, if a branch of a process is in error while another is
still running, this method will consider the process instance inactive
(and it will return true if all the processes are considered inactive). | [
"Returns",
"true",
"if",
"the",
"engine",
"system",
"is",
"inactive",
"ie",
"if",
"all",
"the",
"process",
"instances",
"are",
"terminated",
"or",
"are",
"stuck",
"in",
"an",
"error",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/worker.rb#L149-L166 | train |
jmettraux/ruote | lib/ruote/worker.rb | Ruote.Worker.turn_schedule_to_msg | def turn_schedule_to_msg(schedule)
return false unless @storage.reserve(schedule)
msg = Ruote.fulldup(schedule['msg'])
@storage.put_msg(msg.delete('action'), msg)
true
end | ruby | def turn_schedule_to_msg(schedule)
return false unless @storage.reserve(schedule)
msg = Ruote.fulldup(schedule['msg'])
@storage.put_msg(msg.delete('action'), msg)
true
end | [
"def",
"turn_schedule_to_msg",
"(",
"schedule",
")",
"return",
"false",
"unless",
"@storage",
".",
"reserve",
"(",
"schedule",
")",
"msg",
"=",
"Ruote",
".",
"fulldup",
"(",
"schedule",
"[",
"'msg'",
"]",
")",
"@storage",
".",
"put_msg",
"(",
"msg",
".",
"delete",
"(",
"'action'",
")",
",",
"msg",
")",
"true",
"end"
]
| Given a schedule, attempts to trigger it.
It first tries to reserve the schedule. If the reservation fails
(another worker was successful probably), false is returned.
The schedule is triggered if the reservation was successful, true
is returned. | [
"Given",
"a",
"schedule",
"attempts",
"to",
"trigger",
"it",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/worker.rb#L355-L364 | train |
jmettraux/ruote | lib/ruote/worker.rb | Ruote.Worker.process | def process(msg)
return false unless @storage.reserve(msg)
begin
@context.pre_notify(msg)
case msg['action']
when 'launch', 'apply', 'regenerate'
launch(msg)
when *EXP_ACTIONS
Ruote::Exp::FlowExpression.do_action(@context, msg)
when *DISP_ACTIONS
@context.dispatch_pool.handle(msg)
when *PROC_ACTIONS
self.send(msg['action'], msg)
when 'reput'
reput(msg)
when 'raise'
@context.error_handler.msg_handle(msg['msg'], msg['error'])
when 'respark'
respark(msg)
#else
# no special processing required for message, let it pass
# to the subscribers (the notify two lines after)
end
@context.notify(msg)
# notify subscribers of successfully processed msgs
rescue => err
@context.error_handler.msg_handle(msg, err)
end
@context.storage.done(msg) if @context.storage.respond_to?(:done)
@info << msg if @info
# for the stats
true
end | ruby | def process(msg)
return false unless @storage.reserve(msg)
begin
@context.pre_notify(msg)
case msg['action']
when 'launch', 'apply', 'regenerate'
launch(msg)
when *EXP_ACTIONS
Ruote::Exp::FlowExpression.do_action(@context, msg)
when *DISP_ACTIONS
@context.dispatch_pool.handle(msg)
when *PROC_ACTIONS
self.send(msg['action'], msg)
when 'reput'
reput(msg)
when 'raise'
@context.error_handler.msg_handle(msg['msg'], msg['error'])
when 'respark'
respark(msg)
#else
# no special processing required for message, let it pass
# to the subscribers (the notify two lines after)
end
@context.notify(msg)
# notify subscribers of successfully processed msgs
rescue => err
@context.error_handler.msg_handle(msg, err)
end
@context.storage.done(msg) if @context.storage.respond_to?(:done)
@info << msg if @info
# for the stats
true
end | [
"def",
"process",
"(",
"msg",
")",
"return",
"false",
"unless",
"@storage",
".",
"reserve",
"(",
"msg",
")",
"begin",
"@context",
".",
"pre_notify",
"(",
"msg",
")",
"case",
"msg",
"[",
"'action'",
"]",
"when",
"'launch'",
",",
"'apply'",
",",
"'regenerate'",
"launch",
"(",
"msg",
")",
"when",
"*",
"EXP_ACTIONS",
"Ruote",
"::",
"Exp",
"::",
"FlowExpression",
".",
"do_action",
"(",
"@context",
",",
"msg",
")",
"when",
"*",
"DISP_ACTIONS",
"@context",
".",
"dispatch_pool",
".",
"handle",
"(",
"msg",
")",
"when",
"*",
"PROC_ACTIONS",
"self",
".",
"send",
"(",
"msg",
"[",
"'action'",
"]",
",",
"msg",
")",
"when",
"'reput'",
"reput",
"(",
"msg",
")",
"when",
"'raise'",
"@context",
".",
"error_handler",
".",
"msg_handle",
"(",
"msg",
"[",
"'msg'",
"]",
",",
"msg",
"[",
"'error'",
"]",
")",
"when",
"'respark'",
"respark",
"(",
"msg",
")",
"end",
"@context",
".",
"notify",
"(",
"msg",
")",
"rescue",
"=>",
"err",
"@context",
".",
"error_handler",
".",
"msg_handle",
"(",
"msg",
",",
"err",
")",
"end",
"@context",
".",
"storage",
".",
"done",
"(",
"msg",
")",
"if",
"@context",
".",
"storage",
".",
"respond_to?",
"(",
":done",
")",
"@info",
"<<",
"msg",
"if",
"@info",
"true",
"end"
]
| Processes one msg.
Will return false immediately if the msg reservation failed (another
worker grabbed the message.
Else will execute the action ordered in the msg, and return true.
Exceptions in execution are intercepted here and passed to the
engine's (context's) error_handler. | [
"Processes",
"one",
"msg",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/worker.rb#L376-L433 | train |
jmettraux/ruote | lib/ruote/worker.rb | Ruote.Worker.launch | def launch(msg)
tree = msg['tree']
variables = msg['variables']
wi = msg['workitem']
exp_class = @context.expmap.expression_class(tree.first)
# msg['wfid'] only: it's a launch
# msg['fei']: it's a sub launch (a supplant ?)
if is_launch?(msg, exp_class)
name = tree[1]['name'] || tree[1].keys.find { |k| tree[1][k] == nil }
revision = tree[1]['revision'] || tree[1]['rev']
wi['wf_name'] ||= name
wi['wf_revision'] ||= revision
wi['wf_launched_at'] ||= Ruote.now_to_utc_s
wi['sub_wf_name'] = name
wi['sub_wf_revision'] = revision
wi['sub_wf_launched_at'] = Ruote.now_to_utc_s
end
exp_hash = {
'fei' => msg['fei'] || {
'engine_id' => @context.engine_id,
'wfid' => msg['wfid'],
'subid' => Ruote.generate_subid(msg.inspect),
'expid' => msg['expid'] || '0' },
'parent_id' => msg['parent_id'],
'variables' => variables,
'applied_workitem' => wi,
'forgotten' => msg['forgotten'],
'lost' => msg['lost'],
'flanking' => msg['flanking'],
'attached' => msg['attached'],
'supplanted' => msg['supplanted'],
'stash' => msg['stash'],
'trigger' => msg['trigger'],
'on_reply' => msg['on_reply']
}
if not exp_class
exp_class = Ruote::Exp::RefExpression
elsif is_launch?(msg, exp_class)
def_name, tree = Ruote::Exp::DefineExpression.reorganize(tree)
variables[def_name] = [ '0', tree ] if def_name
exp_class = Ruote::Exp::SequenceExpression
end
exp_hash = exp_hash.reject { |k, v| v.nil? }
# compact nils away
exp_hash['original_tree'] = tree
# keep track of original tree
exp = exp_class.new(@context, exp_hash)
exp.initial_persist
exp.do(:apply, msg)
end | ruby | def launch(msg)
tree = msg['tree']
variables = msg['variables']
wi = msg['workitem']
exp_class = @context.expmap.expression_class(tree.first)
# msg['wfid'] only: it's a launch
# msg['fei']: it's a sub launch (a supplant ?)
if is_launch?(msg, exp_class)
name = tree[1]['name'] || tree[1].keys.find { |k| tree[1][k] == nil }
revision = tree[1]['revision'] || tree[1]['rev']
wi['wf_name'] ||= name
wi['wf_revision'] ||= revision
wi['wf_launched_at'] ||= Ruote.now_to_utc_s
wi['sub_wf_name'] = name
wi['sub_wf_revision'] = revision
wi['sub_wf_launched_at'] = Ruote.now_to_utc_s
end
exp_hash = {
'fei' => msg['fei'] || {
'engine_id' => @context.engine_id,
'wfid' => msg['wfid'],
'subid' => Ruote.generate_subid(msg.inspect),
'expid' => msg['expid'] || '0' },
'parent_id' => msg['parent_id'],
'variables' => variables,
'applied_workitem' => wi,
'forgotten' => msg['forgotten'],
'lost' => msg['lost'],
'flanking' => msg['flanking'],
'attached' => msg['attached'],
'supplanted' => msg['supplanted'],
'stash' => msg['stash'],
'trigger' => msg['trigger'],
'on_reply' => msg['on_reply']
}
if not exp_class
exp_class = Ruote::Exp::RefExpression
elsif is_launch?(msg, exp_class)
def_name, tree = Ruote::Exp::DefineExpression.reorganize(tree)
variables[def_name] = [ '0', tree ] if def_name
exp_class = Ruote::Exp::SequenceExpression
end
exp_hash = exp_hash.reject { |k, v| v.nil? }
# compact nils away
exp_hash['original_tree'] = tree
# keep track of original tree
exp = exp_class.new(@context, exp_hash)
exp.initial_persist
exp.do(:apply, msg)
end | [
"def",
"launch",
"(",
"msg",
")",
"tree",
"=",
"msg",
"[",
"'tree'",
"]",
"variables",
"=",
"msg",
"[",
"'variables'",
"]",
"wi",
"=",
"msg",
"[",
"'workitem'",
"]",
"exp_class",
"=",
"@context",
".",
"expmap",
".",
"expression_class",
"(",
"tree",
".",
"first",
")",
"if",
"is_launch?",
"(",
"msg",
",",
"exp_class",
")",
"name",
"=",
"tree",
"[",
"1",
"]",
"[",
"'name'",
"]",
"||",
"tree",
"[",
"1",
"]",
".",
"keys",
".",
"find",
"{",
"|",
"k",
"|",
"tree",
"[",
"1",
"]",
"[",
"k",
"]",
"==",
"nil",
"}",
"revision",
"=",
"tree",
"[",
"1",
"]",
"[",
"'revision'",
"]",
"||",
"tree",
"[",
"1",
"]",
"[",
"'rev'",
"]",
"wi",
"[",
"'wf_name'",
"]",
"||=",
"name",
"wi",
"[",
"'wf_revision'",
"]",
"||=",
"revision",
"wi",
"[",
"'wf_launched_at'",
"]",
"||=",
"Ruote",
".",
"now_to_utc_s",
"wi",
"[",
"'sub_wf_name'",
"]",
"=",
"name",
"wi",
"[",
"'sub_wf_revision'",
"]",
"=",
"revision",
"wi",
"[",
"'sub_wf_launched_at'",
"]",
"=",
"Ruote",
".",
"now_to_utc_s",
"end",
"exp_hash",
"=",
"{",
"'fei'",
"=>",
"msg",
"[",
"'fei'",
"]",
"||",
"{",
"'engine_id'",
"=>",
"@context",
".",
"engine_id",
",",
"'wfid'",
"=>",
"msg",
"[",
"'wfid'",
"]",
",",
"'subid'",
"=>",
"Ruote",
".",
"generate_subid",
"(",
"msg",
".",
"inspect",
")",
",",
"'expid'",
"=>",
"msg",
"[",
"'expid'",
"]",
"||",
"'0'",
"}",
",",
"'parent_id'",
"=>",
"msg",
"[",
"'parent_id'",
"]",
",",
"'variables'",
"=>",
"variables",
",",
"'applied_workitem'",
"=>",
"wi",
",",
"'forgotten'",
"=>",
"msg",
"[",
"'forgotten'",
"]",
",",
"'lost'",
"=>",
"msg",
"[",
"'lost'",
"]",
",",
"'flanking'",
"=>",
"msg",
"[",
"'flanking'",
"]",
",",
"'attached'",
"=>",
"msg",
"[",
"'attached'",
"]",
",",
"'supplanted'",
"=>",
"msg",
"[",
"'supplanted'",
"]",
",",
"'stash'",
"=>",
"msg",
"[",
"'stash'",
"]",
",",
"'trigger'",
"=>",
"msg",
"[",
"'trigger'",
"]",
",",
"'on_reply'",
"=>",
"msg",
"[",
"'on_reply'",
"]",
"}",
"if",
"not",
"exp_class",
"exp_class",
"=",
"Ruote",
"::",
"Exp",
"::",
"RefExpression",
"elsif",
"is_launch?",
"(",
"msg",
",",
"exp_class",
")",
"def_name",
",",
"tree",
"=",
"Ruote",
"::",
"Exp",
"::",
"DefineExpression",
".",
"reorganize",
"(",
"tree",
")",
"variables",
"[",
"def_name",
"]",
"=",
"[",
"'0'",
",",
"tree",
"]",
"if",
"def_name",
"exp_class",
"=",
"Ruote",
"::",
"Exp",
"::",
"SequenceExpression",
"end",
"exp_hash",
"=",
"exp_hash",
".",
"reject",
"{",
"|",
"k",
",",
"v",
"|",
"v",
".",
"nil?",
"}",
"exp_hash",
"[",
"'original_tree'",
"]",
"=",
"tree",
"exp",
"=",
"exp_class",
".",
"new",
"(",
"@context",
",",
"exp_hash",
")",
"exp",
".",
"initial_persist",
"exp",
".",
"do",
"(",
":apply",
",",
"msg",
")",
"end"
]
| Works for both the 'launch' and the 'apply' msgs.
Creates a new expression, gives and applies it with the
workitem contained in the msg. | [
"Works",
"for",
"both",
"the",
"launch",
"and",
"the",
"apply",
"msgs",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/worker.rb#L440-L509 | train |
jmettraux/ruote | lib/ruote/worker.rb | Ruote.Worker.pause_process | def pause_process(msg)
root = @storage.find_root_expression(msg['wfid'])
return unless root
@storage.put_msg(
msg['action'] == 'pause_process' ? 'pause' : 'resume',
'fei' => root['fei'],
'wfid' => msg['wfid']) # it was triggered by {pause|resume}_process
end | ruby | def pause_process(msg)
root = @storage.find_root_expression(msg['wfid'])
return unless root
@storage.put_msg(
msg['action'] == 'pause_process' ? 'pause' : 'resume',
'fei' => root['fei'],
'wfid' => msg['wfid']) # it was triggered by {pause|resume}_process
end | [
"def",
"pause_process",
"(",
"msg",
")",
"root",
"=",
"@storage",
".",
"find_root_expression",
"(",
"msg",
"[",
"'wfid'",
"]",
")",
"return",
"unless",
"root",
"@storage",
".",
"put_msg",
"(",
"msg",
"[",
"'action'",
"]",
"==",
"'pause_process'",
"?",
"'pause'",
":",
"'resume'",
",",
"'fei'",
"=>",
"root",
"[",
"'fei'",
"]",
",",
"'wfid'",
"=>",
"msg",
"[",
"'wfid'",
"]",
")",
"end"
]
| Handles 'pause_process' and 'resume_process'. | [
"Handles",
"pause_process",
"and",
"resume_process",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/worker.rb#L547-L557 | train |
jmettraux/ruote | lib/ruote/worker.rb | Ruote.Worker.reput | def reput(msg)
if doc = msg['doc']
r = @storage.put(doc)
return unless r.is_a?(Hash)
doc['_rev'] = r['_rev']
reput(msg)
elsif msg = msg['msg']
@storage.put_msg(msg['action'], msg)
end
end | ruby | def reput(msg)
if doc = msg['doc']
r = @storage.put(doc)
return unless r.is_a?(Hash)
doc['_rev'] = r['_rev']
reput(msg)
elsif msg = msg['msg']
@storage.put_msg(msg['action'], msg)
end
end | [
"def",
"reput",
"(",
"msg",
")",
"if",
"doc",
"=",
"msg",
"[",
"'doc'",
"]",
"r",
"=",
"@storage",
".",
"put",
"(",
"doc",
")",
"return",
"unless",
"r",
".",
"is_a?",
"(",
"Hash",
")",
"doc",
"[",
"'_rev'",
"]",
"=",
"r",
"[",
"'_rev'",
"]",
"reput",
"(",
"msg",
")",
"elsif",
"msg",
"=",
"msg",
"[",
"'msg'",
"]",
"@storage",
".",
"put_msg",
"(",
"msg",
"[",
"'action'",
"]",
",",
"msg",
")",
"end",
"end"
]
| Reputs a doc or a msg.
Used by certain storage implementations to pass documents around workers
or to reschedule msgs (see ruote-swf). | [
"Reputs",
"a",
"doc",
"or",
"a",
"msg",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/worker.rb#L566-L582 | train |
jmettraux/ruote | lib/ruote/exp/fe_filter.rb | Ruote::Exp.FilterExpression.block_filter | def block_filter
return nil if tree.last.empty?
tree.last.collect { |line|
next 'or' if line.first == 'or'
rule = line[1].remap { |(k, v), h|
if v == nil
h['field'] = k
else
h[k] = v
end
}
rule['field'] ||= line.first
rule
}
end | ruby | def block_filter
return nil if tree.last.empty?
tree.last.collect { |line|
next 'or' if line.first == 'or'
rule = line[1].remap { |(k, v), h|
if v == nil
h['field'] = k
else
h[k] = v
end
}
rule['field'] ||= line.first
rule
}
end | [
"def",
"block_filter",
"return",
"nil",
"if",
"tree",
".",
"last",
".",
"empty?",
"tree",
".",
"last",
".",
"collect",
"{",
"|",
"line",
"|",
"next",
"'or'",
"if",
"line",
".",
"first",
"==",
"'or'",
"rule",
"=",
"line",
"[",
"1",
"]",
".",
"remap",
"{",
"|",
"(",
"k",
",",
"v",
")",
",",
"h",
"|",
"if",
"v",
"==",
"nil",
"h",
"[",
"'field'",
"]",
"=",
"k",
"else",
"h",
"[",
"k",
"]",
"=",
"v",
"end",
"}",
"rule",
"[",
"'field'",
"]",
"||=",
"line",
".",
"first",
"rule",
"}",
"end"
]
| Filter is passed in a block (which is not evaluted as a ruote branch
but immediately translated into a filter.
pdef = Ruote.process_definition do
filter do
field 'x', :type => 'string'
field 'y', :type => 'number'
end
end
Note : 'or' is OK
pdef = Ruote.process_definition do
filter do
field 'x', :type => 'string'
_or
field 'y', :type => 'number'
end
end | [
"Filter",
"is",
"passed",
"in",
"a",
"block",
"(",
"which",
"is",
"not",
"evaluted",
"as",
"a",
"ruote",
"branch",
"but",
"immediately",
"translated",
"into",
"a",
"filter",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/exp/fe_filter.rb#L599-L619 | train |
jmettraux/ruote | lib/ruote/exp/fe_filter.rb | Ruote::Exp.FilterExpression.one_line_filter | def one_line_filter
if (attributes.keys - COMMON_ATT_KEYS - %w[ ref original_ref ]).empty?
return nil
end
[ attributes.remap { |(k, v), h|
if v.nil?
h['field'] = k
else
h[k] = v
end
} ]
end | ruby | def one_line_filter
if (attributes.keys - COMMON_ATT_KEYS - %w[ ref original_ref ]).empty?
return nil
end
[ attributes.remap { |(k, v), h|
if v.nil?
h['field'] = k
else
h[k] = v
end
} ]
end | [
"def",
"one_line_filter",
"if",
"(",
"attributes",
".",
"keys",
"-",
"COMMON_ATT_KEYS",
"-",
"%w[",
"ref",
"original_ref",
"]",
")",
".",
"empty?",
"return",
"nil",
"end",
"[",
"attributes",
".",
"remap",
"{",
"|",
"(",
"k",
",",
"v",
")",
",",
"h",
"|",
"if",
"v",
".",
"nil?",
"h",
"[",
"'field'",
"]",
"=",
"k",
"else",
"h",
"[",
"k",
"]",
"=",
"v",
"end",
"}",
"]",
"end"
]
| Filter thanks to the attributes of the expression.
pdef = Ruote.process_definition do
filter 'x', :type => 'string', :record => true
filter 'y', :type => 'number', :record => true
end | [
"Filter",
"thanks",
"to",
"the",
"attributes",
"of",
"the",
"expression",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/exp/fe_filter.rb#L662-L675 | train |
jmettraux/ruote | lib/ruote/exp/ro_variables.rb | Ruote::Exp.FlowExpression.compile_variables | def compile_variables
vars = h.parent_id ? parent.compile_variables : {}
vars.merge!(h.variables) if h.variables
vars
end | ruby | def compile_variables
vars = h.parent_id ? parent.compile_variables : {}
vars.merge!(h.variables) if h.variables
vars
end | [
"def",
"compile_variables",
"vars",
"=",
"h",
".",
"parent_id",
"?",
"parent",
".",
"compile_variables",
":",
"{",
"}",
"vars",
".",
"merge!",
"(",
"h",
".",
"variables",
")",
"if",
"h",
".",
"variables",
"vars",
"end"
]
| Returns a fresh hash of all the variables visible from this expression.
This is used mainly when forgetting an expression. | [
"Returns",
"a",
"fresh",
"hash",
"of",
"all",
"the",
"variables",
"visible",
"from",
"this",
"expression",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/exp/ro_variables.rb#L44-L50 | train |
jmettraux/ruote | lib/ruote/exp/ro_variables.rb | Ruote::Exp.FlowExpression.unset_variable | def unset_variable(var, override=false)
fexp, v = locate_set_var(var, override) || locate_var(var)
fexp.un_set_variable(:unset, v, nil, (fexp.h.fei != h.fei)) if fexp
end | ruby | def unset_variable(var, override=false)
fexp, v = locate_set_var(var, override) || locate_var(var)
fexp.un_set_variable(:unset, v, nil, (fexp.h.fei != h.fei)) if fexp
end | [
"def",
"unset_variable",
"(",
"var",
",",
"override",
"=",
"false",
")",
"fexp",
",",
"v",
"=",
"locate_set_var",
"(",
"var",
",",
"override",
")",
"||",
"locate_var",
"(",
"var",
")",
"fexp",
".",
"un_set_variable",
"(",
":unset",
",",
"v",
",",
"nil",
",",
"(",
"fexp",
".",
"h",
".",
"fei",
"!=",
"h",
".",
"fei",
")",
")",
"if",
"fexp",
"end"
]
| Unbinds a variables. | [
"Unbinds",
"a",
"variables",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/exp/ro_variables.rb#L107-L112 | train |
jmettraux/ruote | lib/ruote/exp/ro_variables.rb | Ruote::Exp.FlowExpression.split_prefix | def split_prefix(var, prefix)
if prefix.nil?
m = VAR_PREFIX_REGEX.match(var.to_s)
prefix = m[1]
var = m[2]
end
[ var, prefix ]
end | ruby | def split_prefix(var, prefix)
if prefix.nil?
m = VAR_PREFIX_REGEX.match(var.to_s)
prefix = m[1]
var = m[2]
end
[ var, prefix ]
end | [
"def",
"split_prefix",
"(",
"var",
",",
"prefix",
")",
"if",
"prefix",
".",
"nil?",
"m",
"=",
"VAR_PREFIX_REGEX",
".",
"match",
"(",
"var",
".",
"to_s",
")",
"prefix",
"=",
"m",
"[",
"1",
"]",
"var",
"=",
"m",
"[",
"2",
"]",
"end",
"[",
"var",
",",
"prefix",
"]",
"end"
]
| Used by lookup_variable and set_variable to extract the
prefix in a variable name | [
"Used",
"by",
"lookup_variable",
"and",
"set_variable",
"to",
"extract",
"the",
"prefix",
"in",
"a",
"variable",
"name"
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/exp/ro_variables.rb#L160-L169 | train |
jmettraux/ruote | lib/ruote/dboard/mutation.rb | Ruote.Mutation.walk | def walk(fexp, tree)
ftree = Ruote.compact_tree(@ps.current_tree(fexp))
if ftree[0] != tree[0] || ftree[1] != tree[1]
#
# if there is anything different between the current tree and the
# desired tree, let's force a re-apply
register(MutationPoint.new(fexp.fei, tree, :re_apply))
elsif ftree[2] == tree[2]
#
# else, if the tree children are the same, exit, there is nothing to do
return
else
register(MutationPoint.new(fexp.fei, tree, :update))
#
# NOTE: maybe a switch for this mutation not to be added would
# be necessary...
if fexp.is_concurrent?
#
# concurrent expressions follow a different heuristic
walk_concurrence(fexp, ftree, tree)
else
#
# all other expressions are considered sequence-like
walk_sequence(fexp, ftree, tree)
end
end
end | ruby | def walk(fexp, tree)
ftree = Ruote.compact_tree(@ps.current_tree(fexp))
if ftree[0] != tree[0] || ftree[1] != tree[1]
#
# if there is anything different between the current tree and the
# desired tree, let's force a re-apply
register(MutationPoint.new(fexp.fei, tree, :re_apply))
elsif ftree[2] == tree[2]
#
# else, if the tree children are the same, exit, there is nothing to do
return
else
register(MutationPoint.new(fexp.fei, tree, :update))
#
# NOTE: maybe a switch for this mutation not to be added would
# be necessary...
if fexp.is_concurrent?
#
# concurrent expressions follow a different heuristic
walk_concurrence(fexp, ftree, tree)
else
#
# all other expressions are considered sequence-like
walk_sequence(fexp, ftree, tree)
end
end
end | [
"def",
"walk",
"(",
"fexp",
",",
"tree",
")",
"ftree",
"=",
"Ruote",
".",
"compact_tree",
"(",
"@ps",
".",
"current_tree",
"(",
"fexp",
")",
")",
"if",
"ftree",
"[",
"0",
"]",
"!=",
"tree",
"[",
"0",
"]",
"||",
"ftree",
"[",
"1",
"]",
"!=",
"tree",
"[",
"1",
"]",
"register",
"(",
"MutationPoint",
".",
"new",
"(",
"fexp",
".",
"fei",
",",
"tree",
",",
":re_apply",
")",
")",
"elsif",
"ftree",
"[",
"2",
"]",
"==",
"tree",
"[",
"2",
"]",
"return",
"else",
"register",
"(",
"MutationPoint",
".",
"new",
"(",
"fexp",
".",
"fei",
",",
"tree",
",",
":update",
")",
")",
"if",
"fexp",
".",
"is_concurrent?",
"walk_concurrence",
"(",
"fexp",
",",
"ftree",
",",
"tree",
")",
"else",
"walk_sequence",
"(",
"fexp",
",",
"ftree",
",",
"tree",
")",
"end",
"end",
"end"
]
| Look for mutation points in an expression and its children. | [
"Look",
"for",
"mutation",
"points",
"in",
"an",
"expression",
"and",
"its",
"children",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/dboard/mutation.rb#L146-L183 | train |
jmettraux/ruote | lib/ruote/dboard/mutation.rb | Ruote.Mutation.walk_sequence | def walk_sequence(fexp, ftree, tree)
i = fexp.child_ids.first
ehead = ftree[2].take(i)
ecurrent = ftree[2][i]
etail = ftree[2].drop(i + 1)
head = tree[2].take(i)
current = tree[2][i]
tail = tree[2].drop(i + 1)
if ehead != head
#
# if the name and/or attributes of the exp are supposed to change
# then we have to reapply it
#
register(MutationPoint.new(fexp.fei, tree, :re_apply))
return
end
if ecurrent != current
#
# if the child currently applied is supposed to change, let's walk
# it down
#
walk(@ps.fexp(fexp.children.first), current)
end
#if etail != tail
# #
# # if elements are added at the end of the sequence, let's register
# # a mutation that simply changes the tree (no need to re-apply)
# #
# register(MutationPoint.new(fexp.fei, tree, :update))
#end
end | ruby | def walk_sequence(fexp, ftree, tree)
i = fexp.child_ids.first
ehead = ftree[2].take(i)
ecurrent = ftree[2][i]
etail = ftree[2].drop(i + 1)
head = tree[2].take(i)
current = tree[2][i]
tail = tree[2].drop(i + 1)
if ehead != head
#
# if the name and/or attributes of the exp are supposed to change
# then we have to reapply it
#
register(MutationPoint.new(fexp.fei, tree, :re_apply))
return
end
if ecurrent != current
#
# if the child currently applied is supposed to change, let's walk
# it down
#
walk(@ps.fexp(fexp.children.first), current)
end
#if etail != tail
# #
# # if elements are added at the end of the sequence, let's register
# # a mutation that simply changes the tree (no need to re-apply)
# #
# register(MutationPoint.new(fexp.fei, tree, :update))
#end
end | [
"def",
"walk_sequence",
"(",
"fexp",
",",
"ftree",
",",
"tree",
")",
"i",
"=",
"fexp",
".",
"child_ids",
".",
"first",
"ehead",
"=",
"ftree",
"[",
"2",
"]",
".",
"take",
"(",
"i",
")",
"ecurrent",
"=",
"ftree",
"[",
"2",
"]",
"[",
"i",
"]",
"etail",
"=",
"ftree",
"[",
"2",
"]",
".",
"drop",
"(",
"i",
"+",
"1",
")",
"head",
"=",
"tree",
"[",
"2",
"]",
".",
"take",
"(",
"i",
")",
"current",
"=",
"tree",
"[",
"2",
"]",
"[",
"i",
"]",
"tail",
"=",
"tree",
"[",
"2",
"]",
".",
"drop",
"(",
"i",
"+",
"1",
")",
"if",
"ehead",
"!=",
"head",
"register",
"(",
"MutationPoint",
".",
"new",
"(",
"fexp",
".",
"fei",
",",
"tree",
",",
":re_apply",
")",
")",
"return",
"end",
"if",
"ecurrent",
"!=",
"current",
"walk",
"(",
"@ps",
".",
"fexp",
"(",
"fexp",
".",
"children",
".",
"first",
")",
",",
"current",
")",
"end",
"end"
]
| Look for mutation points in any non-concurrent expression. | [
"Look",
"for",
"mutation",
"points",
"in",
"any",
"non",
"-",
"concurrent",
"expression",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/dboard/mutation.rb#L244-L279 | train |
jmettraux/ruote | lib/ruote/exp/fe_cursor.rb | Ruote::Exp.CursorExpression.move_on | def move_on(workitem=h.applied_workitem)
position = workitem['fei'] == h.fei ?
-1 : Ruote::FlowExpressionId.child_id(workitem['fei'])
position += 1
com, arg = get_command(workitem)
return reply_to_parent(workitem) if com == 'break'
case com
when 'rewind', 'continue', 'reset' then position = 0
when 'skip' then position += arg
when 'jump' then position = jump_to(workitem, position, arg)
end
position = 0 if position >= tree_children.size && is_loop?
if position < tree_children.size
workitem = h.applied_workitem if com == 'reset'
apply_child(position, workitem)
else
reply_to_parent(workitem)
end
end | ruby | def move_on(workitem=h.applied_workitem)
position = workitem['fei'] == h.fei ?
-1 : Ruote::FlowExpressionId.child_id(workitem['fei'])
position += 1
com, arg = get_command(workitem)
return reply_to_parent(workitem) if com == 'break'
case com
when 'rewind', 'continue', 'reset' then position = 0
when 'skip' then position += arg
when 'jump' then position = jump_to(workitem, position, arg)
end
position = 0 if position >= tree_children.size && is_loop?
if position < tree_children.size
workitem = h.applied_workitem if com == 'reset'
apply_child(position, workitem)
else
reply_to_parent(workitem)
end
end | [
"def",
"move_on",
"(",
"workitem",
"=",
"h",
".",
"applied_workitem",
")",
"position",
"=",
"workitem",
"[",
"'fei'",
"]",
"==",
"h",
".",
"fei",
"?",
"-",
"1",
":",
"Ruote",
"::",
"FlowExpressionId",
".",
"child_id",
"(",
"workitem",
"[",
"'fei'",
"]",
")",
"position",
"+=",
"1",
"com",
",",
"arg",
"=",
"get_command",
"(",
"workitem",
")",
"return",
"reply_to_parent",
"(",
"workitem",
")",
"if",
"com",
"==",
"'break'",
"case",
"com",
"when",
"'rewind'",
",",
"'continue'",
",",
"'reset'",
"then",
"position",
"=",
"0",
"when",
"'skip'",
"then",
"position",
"+=",
"arg",
"when",
"'jump'",
"then",
"position",
"=",
"jump_to",
"(",
"workitem",
",",
"position",
",",
"arg",
")",
"end",
"position",
"=",
"0",
"if",
"position",
">=",
"tree_children",
".",
"size",
"&&",
"is_loop?",
"if",
"position",
"<",
"tree_children",
".",
"size",
"workitem",
"=",
"h",
".",
"applied_workitem",
"if",
"com",
"==",
"'reset'",
"apply_child",
"(",
"position",
",",
"workitem",
")",
"else",
"reply_to_parent",
"(",
"workitem",
")",
"end",
"end"
]
| Determines which child expression of the cursor is to be applied next. | [
"Determines",
"which",
"child",
"expression",
"of",
"the",
"cursor",
"is",
"to",
"be",
"applied",
"next",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/exp/fe_cursor.rb#L259-L287 | train |
jmettraux/ruote | lib/ruote/exp/fe_cursor.rb | Ruote::Exp.CursorExpression.jump_to | def jump_to(workitem, position, arg)
pos = Integer(arg) rescue nil
return pos if pos != nil
tree_children.each_with_index do |c, i|
found = [
c[0], # exp_name
c[1]['ref'], # ref
c[1]['tag'], # tag
(c[1].find { |k, v| v.nil? } || []).first # participant 'xxx'
].find do |v|
v ? (dsub(v, workitem) == arg) : false
end
if found then pos = i; break; end
end
pos ? pos : position
end | ruby | def jump_to(workitem, position, arg)
pos = Integer(arg) rescue nil
return pos if pos != nil
tree_children.each_with_index do |c, i|
found = [
c[0], # exp_name
c[1]['ref'], # ref
c[1]['tag'], # tag
(c[1].find { |k, v| v.nil? } || []).first # participant 'xxx'
].find do |v|
v ? (dsub(v, workitem) == arg) : false
end
if found then pos = i; break; end
end
pos ? pos : position
end | [
"def",
"jump_to",
"(",
"workitem",
",",
"position",
",",
"arg",
")",
"pos",
"=",
"Integer",
"(",
"arg",
")",
"rescue",
"nil",
"return",
"pos",
"if",
"pos",
"!=",
"nil",
"tree_children",
".",
"each_with_index",
"do",
"|",
"c",
",",
"i",
"|",
"found",
"=",
"[",
"c",
"[",
"0",
"]",
",",
"c",
"[",
"1",
"]",
"[",
"'ref'",
"]",
",",
"c",
"[",
"1",
"]",
"[",
"'tag'",
"]",
",",
"(",
"c",
"[",
"1",
"]",
".",
"find",
"{",
"|",
"k",
",",
"v",
"|",
"v",
".",
"nil?",
"}",
"||",
"[",
"]",
")",
".",
"first",
"]",
".",
"find",
"do",
"|",
"v",
"|",
"v",
"?",
"(",
"dsub",
"(",
"v",
",",
"workitem",
")",
"==",
"arg",
")",
":",
"false",
"end",
"if",
"found",
"then",
"pos",
"=",
"i",
";",
"break",
";",
"end",
"end",
"pos",
"?",
"pos",
":",
"position",
"end"
]
| Jumps to an integer position, or the name of an expression
or a tag name of a ref name. | [
"Jumps",
"to",
"an",
"integer",
"position",
"or",
"the",
"name",
"of",
"an",
"expression",
"or",
"a",
"tag",
"name",
"of",
"a",
"ref",
"name",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/exp/fe_cursor.rb#L299-L320 | train |
jmettraux/ruote | lib/ruote/storage/base.rb | Ruote.StorageBase.clear | def clear
%w[ msgs schedules errors expressions workitems ].each do |type|
purge_type!(type)
end
end | ruby | def clear
%w[ msgs schedules errors expressions workitems ].each do |type|
purge_type!(type)
end
end | [
"def",
"clear",
"%w[",
"msgs",
"schedules",
"errors",
"expressions",
"workitems",
"]",
".",
"each",
"do",
"|",
"type",
"|",
"purge_type!",
"(",
"type",
")",
"end",
"end"
]
| Used when doing integration tests, removes all
msgs, schedules, errors, expressions and workitems.
NOTE that it doesn't remove engine variables (danger) | [
"Used",
"when",
"doing",
"integration",
"tests",
"removes",
"all",
"msgs",
"schedules",
"errors",
"expressions",
"and",
"workitems",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/storage/base.rb#L267-L272 | train |
jmettraux/ruote | lib/ruote/storage/base.rb | Ruote.StorageBase.remove_process | def remove_process(wfid)
2.times do
# two passes
Thread.pass
%w[ schedules expressions errors workitems ].each do |type|
get_many(type, wfid).each { |d| delete(d) }
end
doc = get_trackers
doc['trackers'].delete_if { |k, v| k.end_with?("!#{wfid}") }
@context.storage.put(doc)
end
end | ruby | def remove_process(wfid)
2.times do
# two passes
Thread.pass
%w[ schedules expressions errors workitems ].each do |type|
get_many(type, wfid).each { |d| delete(d) }
end
doc = get_trackers
doc['trackers'].delete_if { |k, v| k.end_with?("!#{wfid}") }
@context.storage.put(doc)
end
end | [
"def",
"remove_process",
"(",
"wfid",
")",
"2",
".",
"times",
"do",
"Thread",
".",
"pass",
"%w[",
"schedules",
"expressions",
"errors",
"workitems",
"]",
".",
"each",
"do",
"|",
"type",
"|",
"get_many",
"(",
"type",
",",
"wfid",
")",
".",
"each",
"{",
"|",
"d",
"|",
"delete",
"(",
"d",
")",
"}",
"end",
"doc",
"=",
"get_trackers",
"doc",
"[",
"'trackers'",
"]",
".",
"delete_if",
"{",
"|",
"k",
",",
"v",
"|",
"k",
".",
"end_with?",
"(",
"\"!#{wfid}\"",
")",
"}",
"@context",
".",
"storage",
".",
"put",
"(",
"doc",
")",
"end",
"end"
]
| Removes a process by removing all its schedules, expressions, errors,
workitems and trackers.
Warning: will not trigger any cancel behaviours at all, just removes
the process. | [
"Removes",
"a",
"process",
"by",
"removing",
"all",
"its",
"schedules",
"expressions",
"errors",
"workitems",
"and",
"trackers",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/storage/base.rb#L280-L297 | train |
jmettraux/ruote | lib/ruote/storage/base.rb | Ruote.StorageBase.prepare_msg_doc | def prepare_msg_doc(action, options)
# merge! is way faster than merge (no object creation probably)
@counter ||= 0
t = Time.now.utc
ts = "#{t.strftime('%Y-%m-%d')}!#{t.to_i}.#{'%06d' % t.usec}"
_id = "#{$$}!#{Thread.current.object_id}!#{ts}!#{'%03d' % @counter}"
@counter = (@counter + 1) % 1000
# some platforms (windows) have shallow usecs, so adding that counter...
msg = options.merge!('type' => 'msgs', '_id' => _id, 'action' => action)
msg.delete('_rev')
# in case of message replay
msg
end | ruby | def prepare_msg_doc(action, options)
# merge! is way faster than merge (no object creation probably)
@counter ||= 0
t = Time.now.utc
ts = "#{t.strftime('%Y-%m-%d')}!#{t.to_i}.#{'%06d' % t.usec}"
_id = "#{$$}!#{Thread.current.object_id}!#{ts}!#{'%03d' % @counter}"
@counter = (@counter + 1) % 1000
# some platforms (windows) have shallow usecs, so adding that counter...
msg = options.merge!('type' => 'msgs', '_id' => _id, 'action' => action)
msg.delete('_rev')
# in case of message replay
msg
end | [
"def",
"prepare_msg_doc",
"(",
"action",
",",
"options",
")",
"@counter",
"||=",
"0",
"t",
"=",
"Time",
".",
"now",
".",
"utc",
"ts",
"=",
"\"#{t.strftime('%Y-%m-%d')}!#{t.to_i}.#{'%06d' % t.usec}\"",
"_id",
"=",
"\"#{$$}!#{Thread.current.object_id}!#{ts}!#{'%03d' % @counter}\"",
"@counter",
"=",
"(",
"@counter",
"+",
"1",
")",
"%",
"1000",
"msg",
"=",
"options",
".",
"merge!",
"(",
"'type'",
"=>",
"'msgs'",
",",
"'_id'",
"=>",
"_id",
",",
"'action'",
"=>",
"action",
")",
"msg",
".",
"delete",
"(",
"'_rev'",
")",
"msg",
"end"
]
| Used by put_msg | [
"Used",
"by",
"put_msg"
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/storage/base.rb#L310-L329 | train |
jmettraux/ruote | lib/ruote/storage/base.rb | Ruote.StorageBase.prepare_schedule_doc | def prepare_schedule_doc(flavour, owner_fei, s, msg)
at = if s.is_a?(Time) # at or every
s
elsif Ruote.cron_string?(s) # cron
Rufus::Scheduler::CronLine.new(s).next_time(Time.now + 1)
else # at or every
Ruote.s_to_at(s)
end
at = at.utc
if at <= Time.now.utc && flavour == 'at'
put_msg(msg.delete('action'), msg)
return false
end
sat = at.strftime('%Y%m%d%H%M%S')
i = "#{flavour}-#{Ruote.to_storage_id(owner_fei)}-#{sat}"
{
'_id' => i,
'type' => 'schedules',
'flavour' => flavour,
'original' => s,
'at' => Ruote.time_to_utc_s(at),
'owner' => owner_fei,
'wfid' => owner_fei['wfid'],
'msg' => msg
}
end | ruby | def prepare_schedule_doc(flavour, owner_fei, s, msg)
at = if s.is_a?(Time) # at or every
s
elsif Ruote.cron_string?(s) # cron
Rufus::Scheduler::CronLine.new(s).next_time(Time.now + 1)
else # at or every
Ruote.s_to_at(s)
end
at = at.utc
if at <= Time.now.utc && flavour == 'at'
put_msg(msg.delete('action'), msg)
return false
end
sat = at.strftime('%Y%m%d%H%M%S')
i = "#{flavour}-#{Ruote.to_storage_id(owner_fei)}-#{sat}"
{
'_id' => i,
'type' => 'schedules',
'flavour' => flavour,
'original' => s,
'at' => Ruote.time_to_utc_s(at),
'owner' => owner_fei,
'wfid' => owner_fei['wfid'],
'msg' => msg
}
end | [
"def",
"prepare_schedule_doc",
"(",
"flavour",
",",
"owner_fei",
",",
"s",
",",
"msg",
")",
"at",
"=",
"if",
"s",
".",
"is_a?",
"(",
"Time",
")",
"s",
"elsif",
"Ruote",
".",
"cron_string?",
"(",
"s",
")",
"Rufus",
"::",
"Scheduler",
"::",
"CronLine",
".",
"new",
"(",
"s",
")",
".",
"next_time",
"(",
"Time",
".",
"now",
"+",
"1",
")",
"else",
"Ruote",
".",
"s_to_at",
"(",
"s",
")",
"end",
"at",
"=",
"at",
".",
"utc",
"if",
"at",
"<=",
"Time",
".",
"now",
".",
"utc",
"&&",
"flavour",
"==",
"'at'",
"put_msg",
"(",
"msg",
".",
"delete",
"(",
"'action'",
")",
",",
"msg",
")",
"return",
"false",
"end",
"sat",
"=",
"at",
".",
"strftime",
"(",
"'%Y%m%d%H%M%S'",
")",
"i",
"=",
"\"#{flavour}-#{Ruote.to_storage_id(owner_fei)}-#{sat}\"",
"{",
"'_id'",
"=>",
"i",
",",
"'type'",
"=>",
"'schedules'",
",",
"'flavour'",
"=>",
"flavour",
",",
"'original'",
"=>",
"s",
",",
"'at'",
"=>",
"Ruote",
".",
"time_to_utc_s",
"(",
"at",
")",
",",
"'owner'",
"=>",
"owner_fei",
",",
"'wfid'",
"=>",
"owner_fei",
"[",
"'wfid'",
"]",
",",
"'msg'",
"=>",
"msg",
"}",
"end"
]
| Used by put_schedule | [
"Used",
"by",
"put_schedule"
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/storage/base.rb#L333-L362 | train |
jmettraux/ruote | lib/ruote/exp/ro_on_x.rb | Ruote::Exp.FlowExpression.handle_on_error | def handle_on_error(msg, error)
return false if h.state == 'failing'
err = deflate(error)
oe_parent = lookup_on_error(err)
return false unless oe_parent
# no parent with on_error attribute found
handler = oe_parent.local_on_error(err)
return false if handler.to_s == ''
# empty on_error handler nullifies ancestor's on_error
workitem = msg['workitem']
workitem['fields']['__error__'] = err
immediate =
if handler.is_a?(String)
!! handler.match(/^!/)
elsif handler.is_a?(Array)
!! handler.first.to_s.match(/^!/)
else
false
end
# NOTE: why not pass the handler in the msg?
# no, because of HandlerEntry (not JSON serializable)
@context.storage.put_msg(
'fail',
'fei' => oe_parent.h.fei,
'workitem' => workitem,
'immediate' => immediate)
true # yes, error is being handled.
end | ruby | def handle_on_error(msg, error)
return false if h.state == 'failing'
err = deflate(error)
oe_parent = lookup_on_error(err)
return false unless oe_parent
# no parent with on_error attribute found
handler = oe_parent.local_on_error(err)
return false if handler.to_s == ''
# empty on_error handler nullifies ancestor's on_error
workitem = msg['workitem']
workitem['fields']['__error__'] = err
immediate =
if handler.is_a?(String)
!! handler.match(/^!/)
elsif handler.is_a?(Array)
!! handler.first.to_s.match(/^!/)
else
false
end
# NOTE: why not pass the handler in the msg?
# no, because of HandlerEntry (not JSON serializable)
@context.storage.put_msg(
'fail',
'fei' => oe_parent.h.fei,
'workitem' => workitem,
'immediate' => immediate)
true # yes, error is being handled.
end | [
"def",
"handle_on_error",
"(",
"msg",
",",
"error",
")",
"return",
"false",
"if",
"h",
".",
"state",
"==",
"'failing'",
"err",
"=",
"deflate",
"(",
"error",
")",
"oe_parent",
"=",
"lookup_on_error",
"(",
"err",
")",
"return",
"false",
"unless",
"oe_parent",
"handler",
"=",
"oe_parent",
".",
"local_on_error",
"(",
"err",
")",
"return",
"false",
"if",
"handler",
".",
"to_s",
"==",
"''",
"workitem",
"=",
"msg",
"[",
"'workitem'",
"]",
"workitem",
"[",
"'fields'",
"]",
"[",
"'__error__'",
"]",
"=",
"err",
"immediate",
"=",
"if",
"handler",
".",
"is_a?",
"(",
"String",
")",
"!",
"!",
"handler",
".",
"match",
"(",
"/",
"/",
")",
"elsif",
"handler",
".",
"is_a?",
"(",
"Array",
")",
"!",
"!",
"handler",
".",
"first",
".",
"to_s",
".",
"match",
"(",
"/",
"/",
")",
"else",
"false",
"end",
"@context",
".",
"storage",
".",
"put_msg",
"(",
"'fail'",
",",
"'fei'",
"=>",
"oe_parent",
".",
"h",
".",
"fei",
",",
"'workitem'",
"=>",
"workitem",
",",
"'immediate'",
"=>",
"immediate",
")",
"true",
"end"
]
| Looks up parent with on_error attribute and triggers it | [
"Looks",
"up",
"parent",
"with",
"on_error",
"attribute",
"and",
"triggers",
"it"
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/exp/ro_on_x.rb#L68-L105 | train |
jmettraux/ruote | lib/ruote/exp/ro_on_x.rb | Ruote::Exp.FlowExpression.local_on_error | def local_on_error(err)
if h.on_error.is_a?(String) or Ruote.is_tree?(h.on_error)
return h.on_error
end
if h.on_error.is_a?(Array)
# all for the 'on_error' expression
# see test/functional/eft_38_
h.on_error.each do |oe|
if (he = HandlerEntry.new(oe)).match(err)
return he.narrow
end
end
end
nil
end | ruby | def local_on_error(err)
if h.on_error.is_a?(String) or Ruote.is_tree?(h.on_error)
return h.on_error
end
if h.on_error.is_a?(Array)
# all for the 'on_error' expression
# see test/functional/eft_38_
h.on_error.each do |oe|
if (he = HandlerEntry.new(oe)).match(err)
return he.narrow
end
end
end
nil
end | [
"def",
"local_on_error",
"(",
"err",
")",
"if",
"h",
".",
"on_error",
".",
"is_a?",
"(",
"String",
")",
"or",
"Ruote",
".",
"is_tree?",
"(",
"h",
".",
"on_error",
")",
"return",
"h",
".",
"on_error",
"end",
"if",
"h",
".",
"on_error",
".",
"is_a?",
"(",
"Array",
")",
"h",
".",
"on_error",
".",
"each",
"do",
"|",
"oe",
"|",
"if",
"(",
"he",
"=",
"HandlerEntry",
".",
"new",
"(",
"oe",
")",
")",
".",
"match",
"(",
"err",
")",
"return",
"he",
".",
"narrow",
"end",
"end",
"end",
"nil",
"end"
]
| Given an error, returns the on_error registered for it, or nil if none. | [
"Given",
"an",
"error",
"returns",
"the",
"on_error",
"registered",
"for",
"it",
"or",
"nil",
"if",
"none",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/exp/ro_on_x.rb#L167-L188 | train |
jmettraux/ruote | lib/ruote/svc/tracker.rb | Ruote.Tracker.remove | def remove(tracker_ids, wfid)
return if tracker_ids.empty?
doc ||= @context.storage.get_trackers(wfid)
return if (doc['trackers'].keys & tracker_ids).empty?
doc['wfid'] = wfid
# a little helper for some some storage implementations like ruote-swf
# they need to know what workflow execution is targetted.
tracker_ids.each { |ti| doc['trackers'].delete(ti) }
r = @context.storage.put(doc)
remove(tracker_ids, wfid) if r
# the put failed, have to redo the work
end | ruby | def remove(tracker_ids, wfid)
return if tracker_ids.empty?
doc ||= @context.storage.get_trackers(wfid)
return if (doc['trackers'].keys & tracker_ids).empty?
doc['wfid'] = wfid
# a little helper for some some storage implementations like ruote-swf
# they need to know what workflow execution is targetted.
tracker_ids.each { |ti| doc['trackers'].delete(ti) }
r = @context.storage.put(doc)
remove(tracker_ids, wfid) if r
# the put failed, have to redo the work
end | [
"def",
"remove",
"(",
"tracker_ids",
",",
"wfid",
")",
"return",
"if",
"tracker_ids",
".",
"empty?",
"doc",
"||=",
"@context",
".",
"storage",
".",
"get_trackers",
"(",
"wfid",
")",
"return",
"if",
"(",
"doc",
"[",
"'trackers'",
"]",
".",
"keys",
"&",
"tracker_ids",
")",
".",
"empty?",
"doc",
"[",
"'wfid'",
"]",
"=",
"wfid",
"tracker_ids",
".",
"each",
"{",
"|",
"ti",
"|",
"doc",
"[",
"'trackers'",
"]",
".",
"delete",
"(",
"ti",
")",
"}",
"r",
"=",
"@context",
".",
"storage",
".",
"put",
"(",
"doc",
")",
"remove",
"(",
"tracker_ids",
",",
"wfid",
")",
"if",
"r",
"end"
]
| Removes a set of tracker ids and updated the tracker document. | [
"Removes",
"a",
"set",
"of",
"tracker",
"ids",
"and",
"updated",
"the",
"tracker",
"document",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/svc/tracker.rb#L110-L127 | train |
jmettraux/ruote | lib/ruote/svc/tracker.rb | Ruote.Tracker.on_message | def on_message(pre, message)
m_wfid = message['wfid'] || (message['fei']['wfid'] rescue nil)
m_error = message['error']
m_action = message['action']
m_action = "pre_#{m_action}" if pre
msg = m_action == 'error_intercepted' ? message['msg'] : message
ids_to_remove = []
trackers.each do |tracker_id, tracker|
# filter msgs
t_wfid = tracker['wfid']
t_action = tracker['action']
next if t_wfid && t_wfid != m_wfid
next if t_action && t_action != m_action
next unless does_match?(message, tracker['conditions'])
if tracker_id == 'on_error' || tracker_id == 'on_terminate'
fs = msg['workitem']['fields']
next if m_action == 'error_intercepted' && fs['__error__']
next if m_action == 'terminated' && (fs['__error__'] || fs['__terminate__'])
end
# remove the message post-trigger?
ids_to_remove << tracker_id if tracker['msg'].delete('_auto_remove')
# OK, have to pull the trigger (or alter the message) then
if pre && tracker['msg']['_alter']
alter(m_wfid, m_error, m_action, msg, tracker)
else
trigger(m_wfid, m_error, m_action, msg, tracker)
end
end
remove(ids_to_remove, nil)
end | ruby | def on_message(pre, message)
m_wfid = message['wfid'] || (message['fei']['wfid'] rescue nil)
m_error = message['error']
m_action = message['action']
m_action = "pre_#{m_action}" if pre
msg = m_action == 'error_intercepted' ? message['msg'] : message
ids_to_remove = []
trackers.each do |tracker_id, tracker|
# filter msgs
t_wfid = tracker['wfid']
t_action = tracker['action']
next if t_wfid && t_wfid != m_wfid
next if t_action && t_action != m_action
next unless does_match?(message, tracker['conditions'])
if tracker_id == 'on_error' || tracker_id == 'on_terminate'
fs = msg['workitem']['fields']
next if m_action == 'error_intercepted' && fs['__error__']
next if m_action == 'terminated' && (fs['__error__'] || fs['__terminate__'])
end
# remove the message post-trigger?
ids_to_remove << tracker_id if tracker['msg'].delete('_auto_remove')
# OK, have to pull the trigger (or alter the message) then
if pre && tracker['msg']['_alter']
alter(m_wfid, m_error, m_action, msg, tracker)
else
trigger(m_wfid, m_error, m_action, msg, tracker)
end
end
remove(ids_to_remove, nil)
end | [
"def",
"on_message",
"(",
"pre",
",",
"message",
")",
"m_wfid",
"=",
"message",
"[",
"'wfid'",
"]",
"||",
"(",
"message",
"[",
"'fei'",
"]",
"[",
"'wfid'",
"]",
"rescue",
"nil",
")",
"m_error",
"=",
"message",
"[",
"'error'",
"]",
"m_action",
"=",
"message",
"[",
"'action'",
"]",
"m_action",
"=",
"\"pre_#{m_action}\"",
"if",
"pre",
"msg",
"=",
"m_action",
"==",
"'error_intercepted'",
"?",
"message",
"[",
"'msg'",
"]",
":",
"message",
"ids_to_remove",
"=",
"[",
"]",
"trackers",
".",
"each",
"do",
"|",
"tracker_id",
",",
"tracker",
"|",
"t_wfid",
"=",
"tracker",
"[",
"'wfid'",
"]",
"t_action",
"=",
"tracker",
"[",
"'action'",
"]",
"next",
"if",
"t_wfid",
"&&",
"t_wfid",
"!=",
"m_wfid",
"next",
"if",
"t_action",
"&&",
"t_action",
"!=",
"m_action",
"next",
"unless",
"does_match?",
"(",
"message",
",",
"tracker",
"[",
"'conditions'",
"]",
")",
"if",
"tracker_id",
"==",
"'on_error'",
"||",
"tracker_id",
"==",
"'on_terminate'",
"fs",
"=",
"msg",
"[",
"'workitem'",
"]",
"[",
"'fields'",
"]",
"next",
"if",
"m_action",
"==",
"'error_intercepted'",
"&&",
"fs",
"[",
"'__error__'",
"]",
"next",
"if",
"m_action",
"==",
"'terminated'",
"&&",
"(",
"fs",
"[",
"'__error__'",
"]",
"||",
"fs",
"[",
"'__terminate__'",
"]",
")",
"end",
"ids_to_remove",
"<<",
"tracker_id",
"if",
"tracker",
"[",
"'msg'",
"]",
".",
"delete",
"(",
"'_auto_remove'",
")",
"if",
"pre",
"&&",
"tracker",
"[",
"'msg'",
"]",
"[",
"'_alter'",
"]",
"alter",
"(",
"m_wfid",
",",
"m_error",
",",
"m_action",
",",
"msg",
",",
"tracker",
")",
"else",
"trigger",
"(",
"m_wfid",
",",
"m_error",
",",
"m_action",
",",
"msg",
",",
"tracker",
")",
"end",
"end",
"remove",
"(",
"ids_to_remove",
",",
"nil",
")",
"end"
]
| The method behind on_pre_msg and on_msg. Filters msgs against trackers.
Triggers trackers if there is a match. | [
"The",
"method",
"behind",
"on_pre_msg",
"and",
"on_msg",
".",
"Filters",
"msgs",
"against",
"trackers",
".",
"Triggers",
"trackers",
"if",
"there",
"is",
"a",
"match",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/svc/tracker.rb#L132-L178 | train |
jmettraux/ruote | lib/ruote/svc/tracker.rb | Ruote.Tracker.alter | def alter(m_wfid, m_error, m_action, msg, tracker)
case tracker['msg'].delete('_alter')
when 'merge' then msg.merge!(tracker['msg'])
#else ...
end
end | ruby | def alter(m_wfid, m_error, m_action, msg, tracker)
case tracker['msg'].delete('_alter')
when 'merge' then msg.merge!(tracker['msg'])
#else ...
end
end | [
"def",
"alter",
"(",
"m_wfid",
",",
"m_error",
",",
"m_action",
",",
"msg",
",",
"tracker",
")",
"case",
"tracker",
"[",
"'msg'",
"]",
".",
"delete",
"(",
"'_alter'",
")",
"when",
"'merge'",
"then",
"msg",
".",
"merge!",
"(",
"tracker",
"[",
"'msg'",
"]",
")",
"end",
"end"
]
| Alters the msg, only called in "pre" mode. | [
"Alters",
"the",
"msg",
"only",
"called",
"in",
"pre",
"mode",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/svc/tracker.rb#L182-L188 | train |
jmettraux/ruote | lib/ruote/svc/tracker.rb | Ruote.Tracker.trigger | def trigger(m_wfid, m_error, m_action, msg, tracker)
t_action = tracker['action']
tracker_id = tracker['id']
m = Ruote.fulldup(tracker['msg'])
action = m.delete('action')
m['wfid'] = m_wfid if m['wfid'] == 'replace'
m['wfid'] ||= @context.wfidgen.generate
m['workitem'] = msg['workitem'] if m['workitem'] == 'replace'
if t_action == 'error_intercepted'
m['workitem']['fields']['__error__'] = m_error
elsif tracker_id == 'on_error' && m_action == 'error_intercepted'
m['workitem']['fields']['__error__'] = m_error
elsif tracker_id == 'on_terminate' && m_action == 'terminated'
m['workitem']['fields']['__terminate__'] = { 'wfid' => m_wfid }
end
if m['variables'] == 'compile'
fexp = Ruote::Exp::FlowExpression.fetch(@context, msg['fei'])
m['variables'] = fexp ? fexp.compile_variables : {}
end
@context.storage.put_msg(action, m)
end | ruby | def trigger(m_wfid, m_error, m_action, msg, tracker)
t_action = tracker['action']
tracker_id = tracker['id']
m = Ruote.fulldup(tracker['msg'])
action = m.delete('action')
m['wfid'] = m_wfid if m['wfid'] == 'replace'
m['wfid'] ||= @context.wfidgen.generate
m['workitem'] = msg['workitem'] if m['workitem'] == 'replace'
if t_action == 'error_intercepted'
m['workitem']['fields']['__error__'] = m_error
elsif tracker_id == 'on_error' && m_action == 'error_intercepted'
m['workitem']['fields']['__error__'] = m_error
elsif tracker_id == 'on_terminate' && m_action == 'terminated'
m['workitem']['fields']['__terminate__'] = { 'wfid' => m_wfid }
end
if m['variables'] == 'compile'
fexp = Ruote::Exp::FlowExpression.fetch(@context, msg['fei'])
m['variables'] = fexp ? fexp.compile_variables : {}
end
@context.storage.put_msg(action, m)
end | [
"def",
"trigger",
"(",
"m_wfid",
",",
"m_error",
",",
"m_action",
",",
"msg",
",",
"tracker",
")",
"t_action",
"=",
"tracker",
"[",
"'action'",
"]",
"tracker_id",
"=",
"tracker",
"[",
"'id'",
"]",
"m",
"=",
"Ruote",
".",
"fulldup",
"(",
"tracker",
"[",
"'msg'",
"]",
")",
"action",
"=",
"m",
".",
"delete",
"(",
"'action'",
")",
"m",
"[",
"'wfid'",
"]",
"=",
"m_wfid",
"if",
"m",
"[",
"'wfid'",
"]",
"==",
"'replace'",
"m",
"[",
"'wfid'",
"]",
"||=",
"@context",
".",
"wfidgen",
".",
"generate",
"m",
"[",
"'workitem'",
"]",
"=",
"msg",
"[",
"'workitem'",
"]",
"if",
"m",
"[",
"'workitem'",
"]",
"==",
"'replace'",
"if",
"t_action",
"==",
"'error_intercepted'",
"m",
"[",
"'workitem'",
"]",
"[",
"'fields'",
"]",
"[",
"'__error__'",
"]",
"=",
"m_error",
"elsif",
"tracker_id",
"==",
"'on_error'",
"&&",
"m_action",
"==",
"'error_intercepted'",
"m",
"[",
"'workitem'",
"]",
"[",
"'fields'",
"]",
"[",
"'__error__'",
"]",
"=",
"m_error",
"elsif",
"tracker_id",
"==",
"'on_terminate'",
"&&",
"m_action",
"==",
"'terminated'",
"m",
"[",
"'workitem'",
"]",
"[",
"'fields'",
"]",
"[",
"'__terminate__'",
"]",
"=",
"{",
"'wfid'",
"=>",
"m_wfid",
"}",
"end",
"if",
"m",
"[",
"'variables'",
"]",
"==",
"'compile'",
"fexp",
"=",
"Ruote",
"::",
"Exp",
"::",
"FlowExpression",
".",
"fetch",
"(",
"@context",
",",
"msg",
"[",
"'fei'",
"]",
")",
"m",
"[",
"'variables'",
"]",
"=",
"fexp",
"?",
"fexp",
".",
"compile_variables",
":",
"{",
"}",
"end",
"@context",
".",
"storage",
".",
"put_msg",
"(",
"action",
",",
"m",
")",
"end"
]
| Prepares the message that gets placed on the ruote msg queue. | [
"Prepares",
"the",
"message",
"that",
"gets",
"placed",
"on",
"the",
"ruote",
"msg",
"queue",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/svc/tracker.rb#L192-L220 | train |
jmettraux/ruote | lib/ruote/svc/tracker.rb | Ruote.Tracker.does_match? | def does_match?(msg, conditions)
return true unless conditions
conditions.each do |k, v|
return false unless Array(v).find do |vv|
# the Array(v) is for backward compatibility, although newer
# track conditions are already stored as arrays.
vv = Ruote.regex_or_s(vv)
val = case k
when 'class' then msg['error']['class']
when 'message' then msg['error']['message']
else Ruote.lookup(msg, k)
end
val && (vv.is_a?(Regexp) ? vv.match(val) : vv == val)
end
end
true
end | ruby | def does_match?(msg, conditions)
return true unless conditions
conditions.each do |k, v|
return false unless Array(v).find do |vv|
# the Array(v) is for backward compatibility, although newer
# track conditions are already stored as arrays.
vv = Ruote.regex_or_s(vv)
val = case k
when 'class' then msg['error']['class']
when 'message' then msg['error']['message']
else Ruote.lookup(msg, k)
end
val && (vv.is_a?(Regexp) ? vv.match(val) : vv == val)
end
end
true
end | [
"def",
"does_match?",
"(",
"msg",
",",
"conditions",
")",
"return",
"true",
"unless",
"conditions",
"conditions",
".",
"each",
"do",
"|",
"k",
",",
"v",
"|",
"return",
"false",
"unless",
"Array",
"(",
"v",
")",
".",
"find",
"do",
"|",
"vv",
"|",
"vv",
"=",
"Ruote",
".",
"regex_or_s",
"(",
"vv",
")",
"val",
"=",
"case",
"k",
"when",
"'class'",
"then",
"msg",
"[",
"'error'",
"]",
"[",
"'class'",
"]",
"when",
"'message'",
"then",
"msg",
"[",
"'error'",
"]",
"[",
"'message'",
"]",
"else",
"Ruote",
".",
"lookup",
"(",
"msg",
",",
"k",
")",
"end",
"val",
"&&",
"(",
"vv",
".",
"is_a?",
"(",
"Regexp",
")",
"?",
"vv",
".",
"match",
"(",
"val",
")",
":",
"vv",
"==",
"val",
")",
"end",
"end",
"true",
"end"
]
| Given a msg and a hash of conditions, returns true if the msg
matches the conditions. | [
"Given",
"a",
"msg",
"and",
"a",
"hash",
"of",
"conditions",
"returns",
"true",
"if",
"the",
"msg",
"matches",
"the",
"conditions",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/svc/tracker.rb#L236-L262 | train |
jmettraux/ruote | lib/ruote/log/wait_logger.rb | Ruote.WaitLogger.on_msg | def on_msg(msg)
puts(fancy_print(msg, @noisy)) if @noisy
return if msg['action'] == 'noop'
@mutex.synchronize do
@seen << msg
@log << msg
while @log.size > @log_max; @log.shift; end
while @seen.size > @log_max; @seen.shift; end
end
end | ruby | def on_msg(msg)
puts(fancy_print(msg, @noisy)) if @noisy
return if msg['action'] == 'noop'
@mutex.synchronize do
@seen << msg
@log << msg
while @log.size > @log_max; @log.shift; end
while @seen.size > @log_max; @seen.shift; end
end
end | [
"def",
"on_msg",
"(",
"msg",
")",
"puts",
"(",
"fancy_print",
"(",
"msg",
",",
"@noisy",
")",
")",
"if",
"@noisy",
"return",
"if",
"msg",
"[",
"'action'",
"]",
"==",
"'noop'",
"@mutex",
".",
"synchronize",
"do",
"@seen",
"<<",
"msg",
"@log",
"<<",
"msg",
"while",
"@log",
".",
"size",
">",
"@log_max",
";",
"@log",
".",
"shift",
";",
"end",
"while",
"@seen",
".",
"size",
">",
"@log_max",
";",
"@seen",
".",
"shift",
";",
"end",
"end",
"end"
]
| The context will call this method for each msg sucessfully processed
by the worker. | [
"The",
"context",
"will",
"call",
"this",
"method",
"for",
"each",
"msg",
"sucessfully",
"processed",
"by",
"the",
"worker",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/log/wait_logger.rb#L96-L110 | train |
jmettraux/ruote | lib/ruote/log/wait_logger.rb | Ruote.WaitLogger.wait_for | def wait_for(interests, opts={})
@waiting << [ Thread.current, interests ]
Thread.current['__result__'] = nil
start = Time.now
to = opts[:timeout] || @timeout
to = nil if to.nil? || to <= 0
loop do
raise(
Ruote::LoggerTimeout.new(interests, to)
) if to && (Time.now - start) > to
@mutex.synchronize { check_waiting }
break if Thread.current['__result__']
sleep 0.007
end
Thread.current['__result__']
end | ruby | def wait_for(interests, opts={})
@waiting << [ Thread.current, interests ]
Thread.current['__result__'] = nil
start = Time.now
to = opts[:timeout] || @timeout
to = nil if to.nil? || to <= 0
loop do
raise(
Ruote::LoggerTimeout.new(interests, to)
) if to && (Time.now - start) > to
@mutex.synchronize { check_waiting }
break if Thread.current['__result__']
sleep 0.007
end
Thread.current['__result__']
end | [
"def",
"wait_for",
"(",
"interests",
",",
"opts",
"=",
"{",
"}",
")",
"@waiting",
"<<",
"[",
"Thread",
".",
"current",
",",
"interests",
"]",
"Thread",
".",
"current",
"[",
"'__result__'",
"]",
"=",
"nil",
"start",
"=",
"Time",
".",
"now",
"to",
"=",
"opts",
"[",
":timeout",
"]",
"||",
"@timeout",
"to",
"=",
"nil",
"if",
"to",
".",
"nil?",
"||",
"to",
"<=",
"0",
"loop",
"do",
"raise",
"(",
"Ruote",
"::",
"LoggerTimeout",
".",
"new",
"(",
"interests",
",",
"to",
")",
")",
"if",
"to",
"&&",
"(",
"Time",
".",
"now",
"-",
"start",
")",
">",
"to",
"@mutex",
".",
"synchronize",
"{",
"check_waiting",
"}",
"break",
"if",
"Thread",
".",
"current",
"[",
"'__result__'",
"]",
"sleep",
"0.007",
"end",
"Thread",
".",
"current",
"[",
"'__result__'",
"]",
"end"
]
| Blocks until one or more interests are satisfied.
interests must be an array of interests. Please refer to
Dashboard#wait_for documentation for allowed values of each interest.
If multiple interests are given, wait_for blocks until
all of the interests are satisfied.
wait_for may only be used by one thread at a time. If one
thread calls wait_for and later another thread calls wait_for
while the first thread is waiting, the first thread's
interests are lost and the first thread will never wake up. | [
"Blocks",
"until",
"one",
"or",
"more",
"interests",
"are",
"satisfied",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/log/wait_logger.rb#L140-L164 | train |
jmettraux/ruote | lib/ruote/log/wait_logger.rb | Ruote.WaitLogger.matches | def matches(interests, msg)
action = msg['action']
interests.each do |interest|
satisfied = case interest
when :or_error
#
# let's force an immediate reply
interests.clear if action == 'error_intercepted'
when :inactive
(FINAL_ACTIONS.include?(action) && @context.worker.inactive?)
when :empty
(action == 'terminated' && @context.storage.empty?('expressions'))
when Symbol
(action == 'dispatch' && msg['participant_name'] == interest.to_s)
when Fixnum
interests.delete(interest)
if (interest > 1)
interests << (interest - 1)
false
else
true
end
when Hash
interest.all? { |k, v|
k = 'tree.0' if k == 'exp_name'
Ruote.lookup(msg, k) == v
}
when /^[a-z_]+$/
(action == interest)
else # wfid
(FINAL_ACTIONS.include?(action) && msg['wfid'] == interest)
end
interests.delete(interest) if satisfied
end
if interests.include?(:or_error)
(interests.size < 2)
else
(interests.size < 1)
end
end | ruby | def matches(interests, msg)
action = msg['action']
interests.each do |interest|
satisfied = case interest
when :or_error
#
# let's force an immediate reply
interests.clear if action == 'error_intercepted'
when :inactive
(FINAL_ACTIONS.include?(action) && @context.worker.inactive?)
when :empty
(action == 'terminated' && @context.storage.empty?('expressions'))
when Symbol
(action == 'dispatch' && msg['participant_name'] == interest.to_s)
when Fixnum
interests.delete(interest)
if (interest > 1)
interests << (interest - 1)
false
else
true
end
when Hash
interest.all? { |k, v|
k = 'tree.0' if k == 'exp_name'
Ruote.lookup(msg, k) == v
}
when /^[a-z_]+$/
(action == interest)
else # wfid
(FINAL_ACTIONS.include?(action) && msg['wfid'] == interest)
end
interests.delete(interest) if satisfied
end
if interests.include?(:or_error)
(interests.size < 2)
else
(interests.size < 1)
end
end | [
"def",
"matches",
"(",
"interests",
",",
"msg",
")",
"action",
"=",
"msg",
"[",
"'action'",
"]",
"interests",
".",
"each",
"do",
"|",
"interest",
"|",
"satisfied",
"=",
"case",
"interest",
"when",
":or_error",
"interests",
".",
"clear",
"if",
"action",
"==",
"'error_intercepted'",
"when",
":inactive",
"(",
"FINAL_ACTIONS",
".",
"include?",
"(",
"action",
")",
"&&",
"@context",
".",
"worker",
".",
"inactive?",
")",
"when",
":empty",
"(",
"action",
"==",
"'terminated'",
"&&",
"@context",
".",
"storage",
".",
"empty?",
"(",
"'expressions'",
")",
")",
"when",
"Symbol",
"(",
"action",
"==",
"'dispatch'",
"&&",
"msg",
"[",
"'participant_name'",
"]",
"==",
"interest",
".",
"to_s",
")",
"when",
"Fixnum",
"interests",
".",
"delete",
"(",
"interest",
")",
"if",
"(",
"interest",
">",
"1",
")",
"interests",
"<<",
"(",
"interest",
"-",
"1",
")",
"false",
"else",
"true",
"end",
"when",
"Hash",
"interest",
".",
"all?",
"{",
"|",
"k",
",",
"v",
"|",
"k",
"=",
"'tree.0'",
"if",
"k",
"==",
"'exp_name'",
"Ruote",
".",
"lookup",
"(",
"msg",
",",
"k",
")",
"==",
"v",
"}",
"when",
"/",
"/",
"(",
"action",
"==",
"interest",
")",
"else",
"(",
"FINAL_ACTIONS",
".",
"include?",
"(",
"action",
")",
"&&",
"msg",
"[",
"'wfid'",
"]",
"==",
"interest",
")",
"end",
"interests",
".",
"delete",
"(",
"interest",
")",
"if",
"satisfied",
"end",
"if",
"interests",
".",
"include?",
"(",
":or_error",
")",
"(",
"interests",
".",
"size",
"<",
"2",
")",
"else",
"(",
"interests",
".",
"size",
"<",
"1",
")",
"end",
"end"
]
| Checks whether message msg matches any of interests being waited for.
Some interests look for actions on particular workflows (e.g.,
waiting for some workflow to finish). Other interests are not
attached to any particular workflow (e.g., :inactive waits until
the engine finishes processing all active and pending workflows)
but are still satisfied when actions happen on workflows (e.g.,
the last workflow being run finishes).
Returns true if all interests being waited for have been satisfied,
false otherwise. | [
"Checks",
"whether",
"message",
"msg",
"matches",
"any",
"of",
"interests",
"being",
"waited",
"for",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/log/wait_logger.rb#L221-L282 | train |
jmettraux/ruote | lib/ruote/context.rb | Ruote.Context.has_service? | def has_service?(service_name)
service_name = service_name.to_s
service_name = "s_#{service_name}" if ! SERVICE_PREFIX.match(service_name)
@services.has_key?(service_name)
end | ruby | def has_service?(service_name)
service_name = service_name.to_s
service_name = "s_#{service_name}" if ! SERVICE_PREFIX.match(service_name)
@services.has_key?(service_name)
end | [
"def",
"has_service?",
"(",
"service_name",
")",
"service_name",
"=",
"service_name",
".",
"to_s",
"service_name",
"=",
"\"s_#{service_name}\"",
"if",
"!",
"SERVICE_PREFIX",
".",
"match",
"(",
"service_name",
")",
"@services",
".",
"has_key?",
"(",
"service_name",
")",
"end"
]
| Returns true if this context has a given service registered. | [
"Returns",
"true",
"if",
"this",
"context",
"has",
"a",
"given",
"service",
"registered",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/context.rb#L216-L222 | train |
jmettraux/ruote | lib/ruote/exp/ro_persist.rb | Ruote::Exp.FlowExpression.do_p | def do_p(pers)
case r = pers ? try_persist : try_unpersist
when true
false # do not go on
when Hash
self.h = r
self.send("do_#{@msg['action']}", @msg) if @msg
false # do not go on
else
true # success, do go on
end
end | ruby | def do_p(pers)
case r = pers ? try_persist : try_unpersist
when true
false # do not go on
when Hash
self.h = r
self.send("do_#{@msg['action']}", @msg) if @msg
false # do not go on
else
true # success, do go on
end
end | [
"def",
"do_p",
"(",
"pers",
")",
"case",
"r",
"=",
"pers",
"?",
"try_persist",
":",
"try_unpersist",
"when",
"true",
"false",
"when",
"Hash",
"self",
".",
"h",
"=",
"r",
"self",
".",
"send",
"(",
"\"do_#{@msg['action']}\"",
",",
"@msg",
")",
"if",
"@msg",
"false",
"else",
"true",
"end",
"end"
]
| Does persist or unpersist, if successful then returns true. If the
expression is gone, returns false.
If there is a 'fresher' version of the expression, re-attempt and returns
false. | [
"Does",
"persist",
"or",
"unpersist",
"if",
"successful",
"then",
"returns",
"true",
".",
"If",
"the",
"expression",
"is",
"gone",
"returns",
"false",
".",
"If",
"there",
"is",
"a",
"fresher",
"version",
"of",
"the",
"expression",
"re",
"-",
"attempt",
"and",
"returns",
"false",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/exp/ro_persist.rb#L151-L163 | train |
jmettraux/ruote | lib/ruote/part/storage_participant.rb | Ruote.StorageParticipant.on_workitem | def on_workitem
doc = workitem.to_h
doc.merge!(
'type' => 'workitems',
'_id' => to_id(doc['fei']),
'participant_name' => doc['participant_name'],
'wfid' => doc['fei']['wfid'])
doc['store_name'] = @store_name if @store_name
@context.storage.put(doc, :update_rev => true)
end | ruby | def on_workitem
doc = workitem.to_h
doc.merge!(
'type' => 'workitems',
'_id' => to_id(doc['fei']),
'participant_name' => doc['participant_name'],
'wfid' => doc['fei']['wfid'])
doc['store_name'] = @store_name if @store_name
@context.storage.put(doc, :update_rev => true)
end | [
"def",
"on_workitem",
"doc",
"=",
"workitem",
".",
"to_h",
"doc",
".",
"merge!",
"(",
"'type'",
"=>",
"'workitems'",
",",
"'_id'",
"=>",
"to_id",
"(",
"doc",
"[",
"'fei'",
"]",
")",
",",
"'participant_name'",
"=>",
"doc",
"[",
"'participant_name'",
"]",
",",
"'wfid'",
"=>",
"doc",
"[",
"'fei'",
"]",
"[",
"'wfid'",
"]",
")",
"doc",
"[",
"'store_name'",
"]",
"=",
"@store_name",
"if",
"@store_name",
"@context",
".",
"storage",
".",
"put",
"(",
"doc",
",",
":update_rev",
"=>",
"true",
")",
"end"
]
| This is the method called by ruote when passing a workitem to
this participant. | [
"This",
"is",
"the",
"method",
"called",
"by",
"ruote",
"when",
"passing",
"a",
"workitem",
"to",
"this",
"participant",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/part/storage_participant.rb#L80-L93 | train |
jmettraux/ruote | lib/ruote/part/storage_participant.rb | Ruote.StorageParticipant.proceed | def proceed(workitem)
r = remove_workitem('proceed', workitem)
return proceed(workitem) if r != nil
workitem.h.delete('_rev')
reply_to_engine(workitem)
end | ruby | def proceed(workitem)
r = remove_workitem('proceed', workitem)
return proceed(workitem) if r != nil
workitem.h.delete('_rev')
reply_to_engine(workitem)
end | [
"def",
"proceed",
"(",
"workitem",
")",
"r",
"=",
"remove_workitem",
"(",
"'proceed'",
",",
"workitem",
")",
"return",
"proceed",
"(",
"workitem",
")",
"if",
"r",
"!=",
"nil",
"workitem",
".",
"h",
".",
"delete",
"(",
"'_rev'",
")",
"reply_to_engine",
"(",
"workitem",
")",
"end"
]
| Removes the workitem from the storage and replies to the engine. | [
"Removes",
"the",
"workitem",
"from",
"the",
"storage",
"and",
"replies",
"to",
"the",
"engine",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/part/storage_participant.rb#L155-L164 | train |
jmettraux/ruote | lib/ruote/part/storage_participant.rb | Ruote.StorageParticipant.flunk | def flunk(workitem, err_class_or_instance, *err_arguments)
r = remove_workitem('reject', workitem)
return flunk(workitem) if r != nil
workitem.h.delete('_rev')
super(workitem, err_class_or_instance, *err_arguments)
end | ruby | def flunk(workitem, err_class_or_instance, *err_arguments)
r = remove_workitem('reject', workitem)
return flunk(workitem) if r != nil
workitem.h.delete('_rev')
super(workitem, err_class_or_instance, *err_arguments)
end | [
"def",
"flunk",
"(",
"workitem",
",",
"err_class_or_instance",
",",
"*",
"err_arguments",
")",
"r",
"=",
"remove_workitem",
"(",
"'reject'",
",",
"workitem",
")",
"return",
"flunk",
"(",
"workitem",
")",
"if",
"r",
"!=",
"nil",
"workitem",
".",
"h",
".",
"delete",
"(",
"'_rev'",
")",
"super",
"(",
"workitem",
",",
"err_class_or_instance",
",",
"*",
"err_arguments",
")",
"end"
]
| Removes the workitem and hands it back to the flow with an error to
raise for the participant expression that emitted the workitem. | [
"Removes",
"the",
"workitem",
"and",
"hands",
"it",
"back",
"to",
"the",
"flow",
"with",
"an",
"error",
"to",
"raise",
"for",
"the",
"participant",
"expression",
"that",
"emitted",
"the",
"workitem",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/part/storage_participant.rb#L169-L178 | train |
jmettraux/ruote | lib/ruote/part/storage_participant.rb | Ruote.StorageParticipant.all | def all(opts={})
res = fetch_all(opts)
res.is_a?(Array) ? res.map { |hwi| Ruote::Workitem.new(hwi) } : res
end | ruby | def all(opts={})
res = fetch_all(opts)
res.is_a?(Array) ? res.map { |hwi| Ruote::Workitem.new(hwi) } : res
end | [
"def",
"all",
"(",
"opts",
"=",
"{",
"}",
")",
"res",
"=",
"fetch_all",
"(",
"opts",
")",
"res",
".",
"is_a?",
"(",
"Array",
")",
"?",
"res",
".",
"map",
"{",
"|",
"hwi",
"|",
"Ruote",
"::",
"Workitem",
".",
"new",
"(",
"hwi",
")",
"}",
":",
"res",
"end"
]
| Returns all the workitems stored in here. | [
"Returns",
"all",
"the",
"workitems",
"stored",
"in",
"here",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/part/storage_participant.rb#L209-L214 | train |
jmettraux/ruote | lib/ruote/part/storage_participant.rb | Ruote.StorageParticipant.by_wfid | def by_wfid(wfid, opts={})
if @context.storage.respond_to?(:by_wfid)
return @context.storage.by_wfid('workitems', wfid, opts)
end
wis(@context.storage.get_many('workitems', wfid, opts))
end | ruby | def by_wfid(wfid, opts={})
if @context.storage.respond_to?(:by_wfid)
return @context.storage.by_wfid('workitems', wfid, opts)
end
wis(@context.storage.get_many('workitems', wfid, opts))
end | [
"def",
"by_wfid",
"(",
"wfid",
",",
"opts",
"=",
"{",
"}",
")",
"if",
"@context",
".",
"storage",
".",
"respond_to?",
"(",
":by_wfid",
")",
"return",
"@context",
".",
"storage",
".",
"by_wfid",
"(",
"'workitems'",
",",
"wfid",
",",
"opts",
")",
"end",
"wis",
"(",
"@context",
".",
"storage",
".",
"get_many",
"(",
"'workitems'",
",",
"wfid",
",",
"opts",
")",
")",
"end"
]
| Return all workitems for the specified wfid | [
"Return",
"all",
"workitems",
"for",
"the",
"specified",
"wfid"
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/part/storage_participant.rb#L226-L233 | train |
jmettraux/ruote | lib/ruote/part/storage_participant.rb | Ruote.StorageParticipant.by_participant | def by_participant(participant_name, opts={})
return @context.storage.by_participant(
'workitems', participant_name, opts
) if @context.storage.respond_to?(:by_participant)
do_select(opts) do |hwi|
hwi['participant_name'] == participant_name
end
end | ruby | def by_participant(participant_name, opts={})
return @context.storage.by_participant(
'workitems', participant_name, opts
) if @context.storage.respond_to?(:by_participant)
do_select(opts) do |hwi|
hwi['participant_name'] == participant_name
end
end | [
"def",
"by_participant",
"(",
"participant_name",
",",
"opts",
"=",
"{",
"}",
")",
"return",
"@context",
".",
"storage",
".",
"by_participant",
"(",
"'workitems'",
",",
"participant_name",
",",
"opts",
")",
"if",
"@context",
".",
"storage",
".",
"respond_to?",
"(",
":by_participant",
")",
"do_select",
"(",
"opts",
")",
"do",
"|",
"hwi",
"|",
"hwi",
"[",
"'participant_name'",
"]",
"==",
"participant_name",
"end",
"end"
]
| Returns all workitems for the specified participant name | [
"Returns",
"all",
"workitems",
"for",
"the",
"specified",
"participant",
"name"
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/part/storage_participant.rb#L237-L246 | train |
jmettraux/ruote | lib/ruote/part/storage_participant.rb | Ruote.StorageParticipant.query | def query(criteria)
cr = Ruote.keys_to_s(criteria)
if @context.storage.respond_to?(:query_workitems)
return @context.storage.query_workitems(cr)
end
opts = {}
opts[:skip] = cr.delete('offset') || cr.delete('skip')
opts[:limit] = cr.delete('limit')
opts[:count] = cr.delete('count')
wfid = cr.delete('wfid')
count = opts[:count]
pname = cr.delete('participant_name') || cr.delete('participant')
opts.delete(:count) if pname
hwis = wfid ?
@context.storage.get_many('workitems', wfid, opts) : fetch_all(opts)
return hwis unless hwis.is_a?(Array)
hwis = hwis.select { |hwi|
Ruote::StorageParticipant.matches?(hwi, pname, cr)
}
count ? hwis.size : wis(hwis)
end | ruby | def query(criteria)
cr = Ruote.keys_to_s(criteria)
if @context.storage.respond_to?(:query_workitems)
return @context.storage.query_workitems(cr)
end
opts = {}
opts[:skip] = cr.delete('offset') || cr.delete('skip')
opts[:limit] = cr.delete('limit')
opts[:count] = cr.delete('count')
wfid = cr.delete('wfid')
count = opts[:count]
pname = cr.delete('participant_name') || cr.delete('participant')
opts.delete(:count) if pname
hwis = wfid ?
@context.storage.get_many('workitems', wfid, opts) : fetch_all(opts)
return hwis unless hwis.is_a?(Array)
hwis = hwis.select { |hwi|
Ruote::StorageParticipant.matches?(hwi, pname, cr)
}
count ? hwis.size : wis(hwis)
end | [
"def",
"query",
"(",
"criteria",
")",
"cr",
"=",
"Ruote",
".",
"keys_to_s",
"(",
"criteria",
")",
"if",
"@context",
".",
"storage",
".",
"respond_to?",
"(",
":query_workitems",
")",
"return",
"@context",
".",
"storage",
".",
"query_workitems",
"(",
"cr",
")",
"end",
"opts",
"=",
"{",
"}",
"opts",
"[",
":skip",
"]",
"=",
"cr",
".",
"delete",
"(",
"'offset'",
")",
"||",
"cr",
".",
"delete",
"(",
"'skip'",
")",
"opts",
"[",
":limit",
"]",
"=",
"cr",
".",
"delete",
"(",
"'limit'",
")",
"opts",
"[",
":count",
"]",
"=",
"cr",
".",
"delete",
"(",
"'count'",
")",
"wfid",
"=",
"cr",
".",
"delete",
"(",
"'wfid'",
")",
"count",
"=",
"opts",
"[",
":count",
"]",
"pname",
"=",
"cr",
".",
"delete",
"(",
"'participant_name'",
")",
"||",
"cr",
".",
"delete",
"(",
"'participant'",
")",
"opts",
".",
"delete",
"(",
":count",
")",
"if",
"pname",
"hwis",
"=",
"wfid",
"?",
"@context",
".",
"storage",
".",
"get_many",
"(",
"'workitems'",
",",
"wfid",
",",
"opts",
")",
":",
"fetch_all",
"(",
"opts",
")",
"return",
"hwis",
"unless",
"hwis",
".",
"is_a?",
"(",
"Array",
")",
"hwis",
"=",
"hwis",
".",
"select",
"{",
"|",
"hwi",
"|",
"Ruote",
"::",
"StorageParticipant",
".",
"matches?",
"(",
"hwi",
",",
"pname",
",",
"cr",
")",
"}",
"count",
"?",
"hwis",
".",
"size",
":",
"wis",
"(",
"hwis",
")",
"end"
]
| Queries the store participant for workitems.
Some examples :
part.query(:wfid => @wfid).size
part.query('place' => 'nara').size
part.query('place' => 'heiankyou').size
part.query(:wfid => @wfid, :place => 'heiankyou').size
There are two 'reserved' criterion : 'wfid' and 'participant'
('participant_name' as well). The rest of the criteria are considered
constraints for fields.
'offset' and 'limit' are reserved as well. They should prove useful
for pagination. 'skip' can be used instead of 'offset'.
Note : the criteria is AND only, you'll have to do ORs (aggregation)
by yourself. | [
"Queries",
"the",
"store",
"participant",
"for",
"workitems",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/part/storage_participant.rb#L290-L320 | train |
jmettraux/ruote | lib/ruote/part/storage_participant.rb | Ruote.StorageParticipant.per_participant_count | def per_participant_count
per_participant.remap { |(k, v), h| h[k] = v.size }
end | ruby | def per_participant_count
per_participant.remap { |(k, v), h| h[k] = v.size }
end | [
"def",
"per_participant_count",
"per_participant",
".",
"remap",
"{",
"|",
"(",
"k",
",",
"v",
")",
",",
"h",
"|",
"h",
"[",
"k",
"]",
"=",
"v",
".",
"size",
"}",
"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. | [
"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",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/part/storage_participant.rb#L356-L359 | train |
jmettraux/ruote | lib/ruote/part/storage_participant.rb | Ruote.StorageParticipant.delegate | def delegate(workitem, new_owner)
hwi = fetch(workitem)
fail ArgumentError.new(
"workitem not found"
) if hwi == nil
fail ArgumentError.new(
"cannot delegate, workitem doesn't belong to anyone"
) if hwi['owner'] == nil
fail ArgumentError.new(
"cannot delegate, " +
"workitem owned by '#{hwi['owner']}', not '#{workitem.owner}'"
) if hwi['owner'] != workitem.owner
hwi['owner'] = new_owner
r = @context.storage.put(hwi, :update_rev => true)
fail ArgumentError.new("workitem is gone") if r == true
fail ArgumentError.new("workitem got modified meanwhile") if r != nil
Workitem.new(hwi)
end | ruby | def delegate(workitem, new_owner)
hwi = fetch(workitem)
fail ArgumentError.new(
"workitem not found"
) if hwi == nil
fail ArgumentError.new(
"cannot delegate, workitem doesn't belong to anyone"
) if hwi['owner'] == nil
fail ArgumentError.new(
"cannot delegate, " +
"workitem owned by '#{hwi['owner']}', not '#{workitem.owner}'"
) if hwi['owner'] != workitem.owner
hwi['owner'] = new_owner
r = @context.storage.put(hwi, :update_rev => true)
fail ArgumentError.new("workitem is gone") if r == true
fail ArgumentError.new("workitem got modified meanwhile") if r != nil
Workitem.new(hwi)
end | [
"def",
"delegate",
"(",
"workitem",
",",
"new_owner",
")",
"hwi",
"=",
"fetch",
"(",
"workitem",
")",
"fail",
"ArgumentError",
".",
"new",
"(",
"\"workitem not found\"",
")",
"if",
"hwi",
"==",
"nil",
"fail",
"ArgumentError",
".",
"new",
"(",
"\"cannot delegate, workitem doesn't belong to anyone\"",
")",
"if",
"hwi",
"[",
"'owner'",
"]",
"==",
"nil",
"fail",
"ArgumentError",
".",
"new",
"(",
"\"cannot delegate, \"",
"+",
"\"workitem owned by '#{hwi['owner']}', not '#{workitem.owner}'\"",
")",
"if",
"hwi",
"[",
"'owner'",
"]",
"!=",
"workitem",
".",
"owner",
"hwi",
"[",
"'owner'",
"]",
"=",
"new_owner",
"r",
"=",
"@context",
".",
"storage",
".",
"put",
"(",
"hwi",
",",
":update_rev",
"=>",
"true",
")",
"fail",
"ArgumentError",
".",
"new",
"(",
"\"workitem is gone\"",
")",
"if",
"r",
"==",
"true",
"fail",
"ArgumentError",
".",
"new",
"(",
"\"workitem got modified meanwhile\"",
")",
"if",
"r",
"!=",
"nil",
"Workitem",
".",
"new",
"(",
"hwi",
")",
"end"
]
| Delegates a currently owned workitem to a new owner.
Fails if the workitem can't be found, belongs to noone, or if the
workitem passed as argument is out of date (got modified in the mean
time).
It's OK to delegate to nil, thus freeing the workitem.
See #reserve for an an explanation of the reserve/delegate/proceed flow. | [
"Delegates",
"a",
"currently",
"owned",
"workitem",
"to",
"a",
"new",
"owner",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/part/storage_participant.rb#L405-L430 | train |
jmettraux/ruote | lib/ruote/part/storage_participant.rb | Ruote.StorageParticipant.do_select | def do_select(opts, &block)
skip = opts[:offset] || opts[:skip]
limit = opts[:limit]
count = opts[:count]
hwis = fetch_all({})
hwis = hwis.select(&block)
hwis = hwis[skip..-1] if skip
hwis = hwis[0, limit] if limit
return hwis.size if count
hwis.collect { |hwi| Ruote::Workitem.new(hwi) }
end | ruby | def do_select(opts, &block)
skip = opts[:offset] || opts[:skip]
limit = opts[:limit]
count = opts[:count]
hwis = fetch_all({})
hwis = hwis.select(&block)
hwis = hwis[skip..-1] if skip
hwis = hwis[0, limit] if limit
return hwis.size if count
hwis.collect { |hwi| Ruote::Workitem.new(hwi) }
end | [
"def",
"do_select",
"(",
"opts",
",",
"&",
"block",
")",
"skip",
"=",
"opts",
"[",
":offset",
"]",
"||",
"opts",
"[",
":skip",
"]",
"limit",
"=",
"opts",
"[",
":limit",
"]",
"count",
"=",
"opts",
"[",
":count",
"]",
"hwis",
"=",
"fetch_all",
"(",
"{",
"}",
")",
"hwis",
"=",
"hwis",
".",
"select",
"(",
"&",
"block",
")",
"hwis",
"=",
"hwis",
"[",
"skip",
"..",
"-",
"1",
"]",
"if",
"skip",
"hwis",
"=",
"hwis",
"[",
"0",
",",
"limit",
"]",
"if",
"limit",
"return",
"hwis",
".",
"size",
"if",
"count",
"hwis",
".",
"collect",
"{",
"|",
"hwi",
"|",
"Ruote",
"::",
"Workitem",
".",
"new",
"(",
"hwi",
")",
"}",
"end"
]
| Given a few options and a block, returns all the workitems that match
the block | [
"Given",
"a",
"few",
"options",
"and",
"a",
"block",
"returns",
"all",
"the",
"workitems",
"that",
"match",
"the",
"block"
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/part/storage_participant.rb#L457-L472 | train |
jmettraux/ruote | lib/ruote/part/storage_participant.rb | Ruote.StorageParticipant.to_id | def to_id(fei)
a = [ Ruote.to_storage_id(fei) ]
a.unshift(@store_name) if @store_name
a.unshift('wi')
a.join('!')
end | ruby | def to_id(fei)
a = [ Ruote.to_storage_id(fei) ]
a.unshift(@store_name) if @store_name
a.unshift('wi')
a.join('!')
end | [
"def",
"to_id",
"(",
"fei",
")",
"a",
"=",
"[",
"Ruote",
".",
"to_storage_id",
"(",
"fei",
")",
"]",
"a",
".",
"unshift",
"(",
"@store_name",
")",
"if",
"@store_name",
"a",
".",
"unshift",
"(",
"'wi'",
")",
"a",
".",
"join",
"(",
"'!'",
")",
"end"
]
| Computes the id for the document representing the document in the storage. | [
"Computes",
"the",
"id",
"for",
"the",
"document",
"representing",
"the",
"document",
"in",
"the",
"storage",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/part/storage_participant.rb#L476-L485 | train |
jmettraux/ruote | lib/ruote/exp/fe_command.rb | Ruote::Exp.CommandExpression.fetch_command_target | def fetch_command_target(exp=parent)
case exp
when nil then nil
when Ruote::Exp::CommandedExpression then exp
else fetch_command_target(exp.parent)
end
end | ruby | def fetch_command_target(exp=parent)
case exp
when nil then nil
when Ruote::Exp::CommandedExpression then exp
else fetch_command_target(exp.parent)
end
end | [
"def",
"fetch_command_target",
"(",
"exp",
"=",
"parent",
")",
"case",
"exp",
"when",
"nil",
"then",
"nil",
"when",
"Ruote",
"::",
"Exp",
"::",
"CommandedExpression",
"then",
"exp",
"else",
"fetch_command_target",
"(",
"exp",
".",
"parent",
")",
"end",
"end"
]
| Walks up the expression tree (process instance and returns the first
expression that includes the CommandMixin
(CommandExpression includes CommandMixin, but since it doesn't have
children, no need to 'evince' it) | [
"Walks",
"up",
"the",
"expression",
"tree",
"(",
"process",
"instance",
"and",
"returns",
"the",
"first",
"expression",
"that",
"includes",
"the",
"CommandMixin"
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/exp/fe_command.rb#L149-L156 | train |
jmettraux/ruote | lib/ruote/part/rev_participant.rb | Ruote.RevParticipant.lookup_code | def lookup_code
wi = workitem
rev = wi.params['revision'] || wi.params['rev']
[
[ wi.wf_name, wi.wf_revision, wi.participant_name, rev ],
[ wi.wf_name, wi.wf_revision, wi.participant_name ],
[ wi.wf_name, '', wi.participant_name ],
[ wi.participant_name, rev ],
[ wi.participant_name ],
].each do |fname|
fname = File.join(@dir, "#{fname.compact.join('__')}.rb")
next unless File.exist?(fname)
cpart = Class.new
cpart.send(:include, Ruote::LocalParticipant)
cpart.module_eval(File.read(fname))
part = cpart.new
part.context = @context
next if part.respond_to?(:accept?) and (not part.accept?(wi))
return part
end
raise ArgumentError.new(
"couldn't find code for participant #{wi.participant_name} " +
"in dir #{@dir}"
)
end | ruby | def lookup_code
wi = workitem
rev = wi.params['revision'] || wi.params['rev']
[
[ wi.wf_name, wi.wf_revision, wi.participant_name, rev ],
[ wi.wf_name, wi.wf_revision, wi.participant_name ],
[ wi.wf_name, '', wi.participant_name ],
[ wi.participant_name, rev ],
[ wi.participant_name ],
].each do |fname|
fname = File.join(@dir, "#{fname.compact.join('__')}.rb")
next unless File.exist?(fname)
cpart = Class.new
cpart.send(:include, Ruote::LocalParticipant)
cpart.module_eval(File.read(fname))
part = cpart.new
part.context = @context
next if part.respond_to?(:accept?) and (not part.accept?(wi))
return part
end
raise ArgumentError.new(
"couldn't find code for participant #{wi.participant_name} " +
"in dir #{@dir}"
)
end | [
"def",
"lookup_code",
"wi",
"=",
"workitem",
"rev",
"=",
"wi",
".",
"params",
"[",
"'revision'",
"]",
"||",
"wi",
".",
"params",
"[",
"'rev'",
"]",
"[",
"[",
"wi",
".",
"wf_name",
",",
"wi",
".",
"wf_revision",
",",
"wi",
".",
"participant_name",
",",
"rev",
"]",
",",
"[",
"wi",
".",
"wf_name",
",",
"wi",
".",
"wf_revision",
",",
"wi",
".",
"participant_name",
"]",
",",
"[",
"wi",
".",
"wf_name",
",",
"''",
",",
"wi",
".",
"participant_name",
"]",
",",
"[",
"wi",
".",
"participant_name",
",",
"rev",
"]",
",",
"[",
"wi",
".",
"participant_name",
"]",
",",
"]",
".",
"each",
"do",
"|",
"fname",
"|",
"fname",
"=",
"File",
".",
"join",
"(",
"@dir",
",",
"\"#{fname.compact.join('__')}.rb\"",
")",
"next",
"unless",
"File",
".",
"exist?",
"(",
"fname",
")",
"cpart",
"=",
"Class",
".",
"new",
"cpart",
".",
"send",
"(",
":include",
",",
"Ruote",
"::",
"LocalParticipant",
")",
"cpart",
".",
"module_eval",
"(",
"File",
".",
"read",
"(",
"fname",
")",
")",
"part",
"=",
"cpart",
".",
"new",
"part",
".",
"context",
"=",
"@context",
"next",
"if",
"part",
".",
"respond_to?",
"(",
":accept?",
")",
"and",
"(",
"not",
"part",
".",
"accept?",
"(",
"wi",
")",
")",
"return",
"part",
"end",
"raise",
"ArgumentError",
".",
"new",
"(",
"\"couldn't find code for participant #{wi.participant_name} \"",
"+",
"\"in dir #{@dir}\"",
")",
"end"
]
| Maybe "lookup_real_participant_code" would be a better name... | [
"Maybe",
"lookup_real_participant_code",
"would",
"be",
"a",
"better",
"name",
"..."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/part/rev_participant.rb#L143-L175 | train |
jmettraux/ruote | lib/ruote/exp/fe_if.rb | Ruote::Exp.IfExpression.reply | def reply(workitem)
if workitem['fei'] == h.fei # apply --> reply
h.test = attribute(:test)
h.test = attribute(:t) if h.test.nil?
h.test = attribute_text if h.test.nil?
h.test = nil if h.test == ''
offset = (h.test.nil? || Condition.true?(h.test)) ? 0 : 1
apply_child(offset, workitem)
else # reply from a child
if h.test != nil || Ruote::FlowExpressionId.child_id(workitem['fei']) != 0
reply_to_parent(workitem)
else
apply_child(workitem['fields']['__result__'] == true ? 1 : 2, workitem)
end
end
end | ruby | def reply(workitem)
if workitem['fei'] == h.fei # apply --> reply
h.test = attribute(:test)
h.test = attribute(:t) if h.test.nil?
h.test = attribute_text if h.test.nil?
h.test = nil if h.test == ''
offset = (h.test.nil? || Condition.true?(h.test)) ? 0 : 1
apply_child(offset, workitem)
else # reply from a child
if h.test != nil || Ruote::FlowExpressionId.child_id(workitem['fei']) != 0
reply_to_parent(workitem)
else
apply_child(workitem['fields']['__result__'] == true ? 1 : 2, workitem)
end
end
end | [
"def",
"reply",
"(",
"workitem",
")",
"if",
"workitem",
"[",
"'fei'",
"]",
"==",
"h",
".",
"fei",
"h",
".",
"test",
"=",
"attribute",
"(",
":test",
")",
"h",
".",
"test",
"=",
"attribute",
"(",
":t",
")",
"if",
"h",
".",
"test",
".",
"nil?",
"h",
".",
"test",
"=",
"attribute_text",
"if",
"h",
".",
"test",
".",
"nil?",
"h",
".",
"test",
"=",
"nil",
"if",
"h",
".",
"test",
"==",
"''",
"offset",
"=",
"(",
"h",
".",
"test",
".",
"nil?",
"||",
"Condition",
".",
"true?",
"(",
"h",
".",
"test",
")",
")",
"?",
"0",
":",
"1",
"apply_child",
"(",
"offset",
",",
"workitem",
")",
"else",
"if",
"h",
".",
"test",
"!=",
"nil",
"||",
"Ruote",
"::",
"FlowExpressionId",
".",
"child_id",
"(",
"workitem",
"[",
"'fei'",
"]",
")",
"!=",
"0",
"reply_to_parent",
"(",
"workitem",
")",
"else",
"apply_child",
"(",
"workitem",
"[",
"'fields'",
"]",
"[",
"'__result__'",
"]",
"==",
"true",
"?",
"1",
":",
"2",
",",
"workitem",
")",
"end",
"end",
"end"
]
| called by 'else', 'then' or perhaps 'equals' | [
"called",
"by",
"else",
"then",
"or",
"perhaps",
"equals"
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/exp/fe_if.rb#L169-L193 | train |
jmettraux/ruote | lib/ruote/svc/participant_list.rb | Ruote.ParticipantList.unregister | def unregister(name_or_participant)
code = nil
entry = nil
list = get_list
name_or_participant = name_or_participant.to_s
entry = list['list'].find { |re, pa| name_or_participant.match(re) }
return nil unless entry
code = entry.last if entry.last.is_a?(String)
list['list'].delete(entry)
if r = @context.storage.put(list)
#
# put failed, have to redo it
#
return unregister(name_or_participant)
end
entry.first
end | ruby | def unregister(name_or_participant)
code = nil
entry = nil
list = get_list
name_or_participant = name_or_participant.to_s
entry = list['list'].find { |re, pa| name_or_participant.match(re) }
return nil unless entry
code = entry.last if entry.last.is_a?(String)
list['list'].delete(entry)
if r = @context.storage.put(list)
#
# put failed, have to redo it
#
return unregister(name_or_participant)
end
entry.first
end | [
"def",
"unregister",
"(",
"name_or_participant",
")",
"code",
"=",
"nil",
"entry",
"=",
"nil",
"list",
"=",
"get_list",
"name_or_participant",
"=",
"name_or_participant",
".",
"to_s",
"entry",
"=",
"list",
"[",
"'list'",
"]",
".",
"find",
"{",
"|",
"re",
",",
"pa",
"|",
"name_or_participant",
".",
"match",
"(",
"re",
")",
"}",
"return",
"nil",
"unless",
"entry",
"code",
"=",
"entry",
".",
"last",
"if",
"entry",
".",
"last",
".",
"is_a?",
"(",
"String",
")",
"list",
"[",
"'list'",
"]",
".",
"delete",
"(",
"entry",
")",
"if",
"r",
"=",
"@context",
".",
"storage",
".",
"put",
"(",
"list",
")",
"return",
"unregister",
"(",
"name_or_participant",
")",
"end",
"entry",
".",
"first",
"end"
]
| Removes a participant, given via its name or directly from this
participant list.
Called usually by Engine#unregister_participant. | [
"Removes",
"a",
"participant",
"given",
"via",
"its",
"name",
"or",
"directly",
"from",
"this",
"participant",
"list",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/svc/participant_list.rb#L140-L164 | train |
jmettraux/ruote | lib/ruote/svc/participant_list.rb | Ruote.ParticipantList.lookup | def lookup(participant_name, workitem, opts={})
pinfo = participant_name.is_a?(String) ?
lookup_info(participant_name, workitem) : participant_name
instantiate(pinfo, opts)
end | ruby | def lookup(participant_name, workitem, opts={})
pinfo = participant_name.is_a?(String) ?
lookup_info(participant_name, workitem) : participant_name
instantiate(pinfo, opts)
end | [
"def",
"lookup",
"(",
"participant_name",
",",
"workitem",
",",
"opts",
"=",
"{",
"}",
")",
"pinfo",
"=",
"participant_name",
".",
"is_a?",
"(",
"String",
")",
"?",
"lookup_info",
"(",
"participant_name",
",",
"workitem",
")",
":",
"participant_name",
"instantiate",
"(",
"pinfo",
",",
"opts",
")",
"end"
]
| Returns a participant instance, or nil if there is no participant
for the given participant name.
Mostly a combination of #lookup_info and #instantiate. | [
"Returns",
"a",
"participant",
"instance",
"or",
"nil",
"if",
"there",
"is",
"no",
"participant",
"for",
"the",
"given",
"participant",
"name",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/svc/participant_list.rb#L171-L177 | train |
jmettraux/ruote | lib/ruote/svc/participant_list.rb | Ruote.ParticipantList.lookup_info | def lookup_info(pname, workitem)
return nil unless pname
wi = workitem ?
Ruote::Workitem.new(workitem.merge('participant_name' => pname)) :
nil
get_list['list'].each do |regex, pinfo|
next unless pname.match(regex)
return pinfo if workitem.nil?
pa = instantiate(pinfo, :if_respond_to? => :accept?)
return pinfo if pa.nil?
return pinfo if Ruote.participant_send(pa, :accept?, 'workitem' => wi)
end
# nothing found...
nil
end | ruby | def lookup_info(pname, workitem)
return nil unless pname
wi = workitem ?
Ruote::Workitem.new(workitem.merge('participant_name' => pname)) :
nil
get_list['list'].each do |regex, pinfo|
next unless pname.match(regex)
return pinfo if workitem.nil?
pa = instantiate(pinfo, :if_respond_to? => :accept?)
return pinfo if pa.nil?
return pinfo if Ruote.participant_send(pa, :accept?, 'workitem' => wi)
end
# nothing found...
nil
end | [
"def",
"lookup_info",
"(",
"pname",
",",
"workitem",
")",
"return",
"nil",
"unless",
"pname",
"wi",
"=",
"workitem",
"?",
"Ruote",
"::",
"Workitem",
".",
"new",
"(",
"workitem",
".",
"merge",
"(",
"'participant_name'",
"=>",
"pname",
")",
")",
":",
"nil",
"get_list",
"[",
"'list'",
"]",
".",
"each",
"do",
"|",
"regex",
",",
"pinfo",
"|",
"next",
"unless",
"pname",
".",
"match",
"(",
"regex",
")",
"return",
"pinfo",
"if",
"workitem",
".",
"nil?",
"pa",
"=",
"instantiate",
"(",
"pinfo",
",",
":if_respond_to?",
"=>",
":accept?",
")",
"return",
"pinfo",
"if",
"pa",
".",
"nil?",
"return",
"pinfo",
"if",
"Ruote",
".",
"participant_send",
"(",
"pa",
",",
":accept?",
",",
"'workitem'",
"=>",
"wi",
")",
"end",
"nil",
"end"
]
| Given a participant name, returns participant details.
Returns nil if there is no participant registered that covers the given
participant name. | [
"Given",
"a",
"participant",
"name",
"returns",
"participant",
"details",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/svc/participant_list.rb#L184-L207 | train |
jmettraux/ruote | lib/ruote/svc/participant_list.rb | Ruote.ParticipantList.instantiate | def instantiate(pinfo, opts={})
return nil unless pinfo
pa_class_name, options = pinfo
if rp = options['require_path']
require(rp)
end
if lp = options['load_path']
load(lp)
end
pa_class = Ruote.constantize(pa_class_name)
pa_m = pa_class.instance_methods
irt = opts[:if_respond_to?]
if irt && ! (pa_m.include?(irt.to_s) || pa_m.include?(irt.to_sym))
return nil
end
initialize_participant(pa_class, options)
end | ruby | def instantiate(pinfo, opts={})
return nil unless pinfo
pa_class_name, options = pinfo
if rp = options['require_path']
require(rp)
end
if lp = options['load_path']
load(lp)
end
pa_class = Ruote.constantize(pa_class_name)
pa_m = pa_class.instance_methods
irt = opts[:if_respond_to?]
if irt && ! (pa_m.include?(irt.to_s) || pa_m.include?(irt.to_sym))
return nil
end
initialize_participant(pa_class, options)
end | [
"def",
"instantiate",
"(",
"pinfo",
",",
"opts",
"=",
"{",
"}",
")",
"return",
"nil",
"unless",
"pinfo",
"pa_class_name",
",",
"options",
"=",
"pinfo",
"if",
"rp",
"=",
"options",
"[",
"'require_path'",
"]",
"require",
"(",
"rp",
")",
"end",
"if",
"lp",
"=",
"options",
"[",
"'load_path'",
"]",
"load",
"(",
"lp",
")",
"end",
"pa_class",
"=",
"Ruote",
".",
"constantize",
"(",
"pa_class_name",
")",
"pa_m",
"=",
"pa_class",
".",
"instance_methods",
"irt",
"=",
"opts",
"[",
":if_respond_to?",
"]",
"if",
"irt",
"&&",
"!",
"(",
"pa_m",
".",
"include?",
"(",
"irt",
".",
"to_s",
")",
"||",
"pa_m",
".",
"include?",
"(",
"irt",
".",
"to_sym",
")",
")",
"return",
"nil",
"end",
"initialize_participant",
"(",
"pa_class",
",",
"options",
")",
"end"
]
| Returns an instance of a participant. | [
"Returns",
"an",
"instance",
"of",
"a",
"participant",
"."
]
| 30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c | https://github.com/jmettraux/ruote/blob/30a6bb88a4e48ed2e1b9089754f1c8be8c1a879c/lib/ruote/svc/participant_list.rb#L211-L234 | train |
icoretech/spotify-client | lib/spotify_client.rb | Spotify.Client.create_user_playlist | def create_user_playlist(user_id, name, is_public = true)
run(:post, "/v1/users/#{user_id}/playlists", [201], JSON.dump(name: name, public: is_public), false)
end | ruby | def create_user_playlist(user_id, name, is_public = true)
run(:post, "/v1/users/#{user_id}/playlists", [201], JSON.dump(name: name, public: is_public), false)
end | [
"def",
"create_user_playlist",
"(",
"user_id",
",",
"name",
",",
"is_public",
"=",
"true",
")",
"run",
"(",
":post",
",",
"\"/v1/users/#{user_id}/playlists\"",
",",
"[",
"201",
"]",
",",
"JSON",
".",
"dump",
"(",
"name",
":",
"name",
",",
"public",
":",
"is_public",
")",
",",
"false",
")",
"end"
]
| Create a playlist for a Spotify user. The playlist will be empty until you add tracks.
Requires playlist-modify-public for a public playlist.
Requires playlist-modify-private for a private playlist. | [
"Create",
"a",
"playlist",
"for",
"a",
"Spotify",
"user",
".",
"The",
"playlist",
"will",
"be",
"empty",
"until",
"you",
"add",
"tracks",
"."
]
| 2368530f0f509a5123c44d40f79a8ea11ce61394 | https://github.com/icoretech/spotify-client/blob/2368530f0f509a5123c44d40f79a8ea11ce61394/lib/spotify_client.rb#L91-L93 | train |
icoretech/spotify-client | lib/spotify_client.rb | Spotify.Client.add_user_tracks_to_playlist | def add_user_tracks_to_playlist(user_id, playlist_id, uris = [], position = nil)
params = { uris: Array.wrap(uris)[0..99].join(',') }
if position
params.merge!(position: position)
end
run(:post, "/v1/users/#{user_id}/playlists/#{playlist_id}/tracks", [201], JSON.dump(params), false)
end | ruby | def add_user_tracks_to_playlist(user_id, playlist_id, uris = [], position = nil)
params = { uris: Array.wrap(uris)[0..99].join(',') }
if position
params.merge!(position: position)
end
run(:post, "/v1/users/#{user_id}/playlists/#{playlist_id}/tracks", [201], JSON.dump(params), false)
end | [
"def",
"add_user_tracks_to_playlist",
"(",
"user_id",
",",
"playlist_id",
",",
"uris",
"=",
"[",
"]",
",",
"position",
"=",
"nil",
")",
"params",
"=",
"{",
"uris",
":",
"Array",
".",
"wrap",
"(",
"uris",
")",
"[",
"0",
"..",
"99",
"]",
".",
"join",
"(",
"','",
")",
"}",
"if",
"position",
"params",
".",
"merge!",
"(",
"position",
":",
"position",
")",
"end",
"run",
"(",
":post",
",",
"\"/v1/users/#{user_id}/playlists/#{playlist_id}/tracks\"",
",",
"[",
"201",
"]",
",",
"JSON",
".",
"dump",
"(",
"params",
")",
",",
"false",
")",
"end"
]
| Add an Array of track uris to an existing playlist.
Adding tracks to a user's public playlist requires authorization of the playlist-modify-public scope;
adding tracks to a private playlist requires the playlist-modify-private scope.
client.add_user_tracks_to_playlist('1181346016', '7i3thJWDtmX04dJhFwYb0x', %w(spotify:track:4iV5W9uYEdYUVa79Axb7Rh spotify:track:2lzEz3A3XIFyhMDqzMdcss)) | [
"Add",
"an",
"Array",
"of",
"track",
"uris",
"to",
"an",
"existing",
"playlist",
"."
]
| 2368530f0f509a5123c44d40f79a8ea11ce61394 | https://github.com/icoretech/spotify-client/blob/2368530f0f509a5123c44d40f79a8ea11ce61394/lib/spotify_client.rb#L101-L107 | train |
icoretech/spotify-client | lib/spotify_client.rb | Spotify.Client.follow | def follow(type, ids)
params = { type: type, ids: Array.wrap(ids).join(',') }
run(:put, "/v1/me/following", [204], params)
end | ruby | def follow(type, ids)
params = { type: type, ids: Array.wrap(ids).join(',') }
run(:put, "/v1/me/following", [204], params)
end | [
"def",
"follow",
"(",
"type",
",",
"ids",
")",
"params",
"=",
"{",
"type",
":",
"type",
",",
"ids",
":",
"Array",
".",
"wrap",
"(",
"ids",
")",
".",
"join",
"(",
"','",
")",
"}",
"run",
"(",
":put",
",",
"\"/v1/me/following\"",
",",
"[",
"204",
"]",
",",
"params",
")",
"end"
]
| Follow artists or users
client.follow('artist', ['0BvkDsjIUla7X0k6CSWh1I']) | [
"Follow",
"artists",
"or",
"users"
]
| 2368530f0f509a5123c44d40f79a8ea11ce61394 | https://github.com/icoretech/spotify-client/blob/2368530f0f509a5123c44d40f79a8ea11ce61394/lib/spotify_client.rb#L186-L189 | train |
matiaskorhonen/monit | lib/monit/status.rb | Monit.Status.url | def url
url_params = { :host => @host, :port => @port, :path => "/_status", :query => "format=xml" }
@ssl ? URI::HTTPS.build(url_params) : URI::HTTP.build(url_params)
end | ruby | def url
url_params = { :host => @host, :port => @port, :path => "/_status", :query => "format=xml" }
@ssl ? URI::HTTPS.build(url_params) : URI::HTTP.build(url_params)
end | [
"def",
"url",
"url_params",
"=",
"{",
":host",
"=>",
"@host",
",",
":port",
"=>",
"@port",
",",
":path",
"=>",
"\"/_status\"",
",",
":query",
"=>",
"\"format=xml\"",
"}",
"@ssl",
"?",
"URI",
"::",
"HTTPS",
".",
"build",
"(",
"url_params",
")",
":",
"URI",
"::",
"HTTP",
".",
"build",
"(",
"url_params",
")",
"end"
]
| Create a new instance of the status class with the given options
<b>Options:</b>
* +host+ - the host for monit, defaults to +localhost+
* +port+ - the Monit port, defaults to +2812+
* +ssl+ - should we use SSL for the connection to Monit (default: false)
* +auth+ - should authentication be used, defaults to false
* +username+ - username for authentication
* +password+ - password for authentication
Construct the URL | [
"Create",
"a",
"new",
"instance",
"of",
"the",
"status",
"class",
"with",
"the",
"given",
"options"
]
| ace938155259e269e4ba492bec6e24502d33a8cf | https://github.com/matiaskorhonen/monit/blob/ace938155259e269e4ba492bec6e24502d33a8cf/lib/monit/status.rb#L40-L43 | train |
matiaskorhonen/monit | lib/monit/status.rb | Monit.Status.get | def get
uri = self.url
http = Net::HTTP.new(uri.host, uri.port)
if @ssl
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
request = Net::HTTP::Get.new(uri.request_uri)
if @auth
request.basic_auth(@username, @password)
end
request["User-Agent"] = "Monit Ruby client #{Monit::VERSION}"
begin
response = http.request(request)
rescue Errno::ECONNREFUSED
return false
end
if (response.code =~ /\A2\d\d\z/)
@xml = response.body
return self.parse(@xml)
else
return false
end
end | ruby | def get
uri = self.url
http = Net::HTTP.new(uri.host, uri.port)
if @ssl
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
request = Net::HTTP::Get.new(uri.request_uri)
if @auth
request.basic_auth(@username, @password)
end
request["User-Agent"] = "Monit Ruby client #{Monit::VERSION}"
begin
response = http.request(request)
rescue Errno::ECONNREFUSED
return false
end
if (response.code =~ /\A2\d\d\z/)
@xml = response.body
return self.parse(@xml)
else
return false
end
end | [
"def",
"get",
"uri",
"=",
"self",
".",
"url",
"http",
"=",
"Net",
"::",
"HTTP",
".",
"new",
"(",
"uri",
".",
"host",
",",
"uri",
".",
"port",
")",
"if",
"@ssl",
"http",
".",
"use_ssl",
"=",
"true",
"http",
".",
"verify_mode",
"=",
"OpenSSL",
"::",
"SSL",
"::",
"VERIFY_NONE",
"end",
"request",
"=",
"Net",
"::",
"HTTP",
"::",
"Get",
".",
"new",
"(",
"uri",
".",
"request_uri",
")",
"if",
"@auth",
"request",
".",
"basic_auth",
"(",
"@username",
",",
"@password",
")",
"end",
"request",
"[",
"\"User-Agent\"",
"]",
"=",
"\"Monit Ruby client #{Monit::VERSION}\"",
"begin",
"response",
"=",
"http",
".",
"request",
"(",
"request",
")",
"rescue",
"Errno",
"::",
"ECONNREFUSED",
"return",
"false",
"end",
"if",
"(",
"response",
".",
"code",
"=~",
"/",
"\\A",
"\\d",
"\\d",
"\\z",
"/",
")",
"@xml",
"=",
"response",
".",
"body",
"return",
"self",
".",
"parse",
"(",
"@xml",
")",
"else",
"return",
"false",
"end",
"end"
]
| Get the status from Monit. | [
"Get",
"the",
"status",
"from",
"Monit",
"."
]
| ace938155259e269e4ba492bec6e24502d33a8cf | https://github.com/matiaskorhonen/monit/blob/ace938155259e269e4ba492bec6e24502d33a8cf/lib/monit/status.rb#L46-L75 | train |
matiaskorhonen/monit | lib/monit/status.rb | Monit.Status.parse | def parse(xml)
@hash = Hash.from_xml(xml)
@server = Server.new(@hash["monit"]["server"])
@platform = Platform.new(@hash["monit"]["platform"])
options = {
:host => @host,
:port => @port,
:ssl => @ssl,
:auth => @auth,
:username => @username,
:password => @password
}
if @hash["monit"]["service"].is_a? Array
@services = @hash["monit"]["service"].map do |service|
Service.new(service, options)
end
else
@services = [Service.new(@hash["monit"]["service"], options)]
end
true
rescue
false
end | ruby | def parse(xml)
@hash = Hash.from_xml(xml)
@server = Server.new(@hash["monit"]["server"])
@platform = Platform.new(@hash["monit"]["platform"])
options = {
:host => @host,
:port => @port,
:ssl => @ssl,
:auth => @auth,
:username => @username,
:password => @password
}
if @hash["monit"]["service"].is_a? Array
@services = @hash["monit"]["service"].map do |service|
Service.new(service, options)
end
else
@services = [Service.new(@hash["monit"]["service"], options)]
end
true
rescue
false
end | [
"def",
"parse",
"(",
"xml",
")",
"@hash",
"=",
"Hash",
".",
"from_xml",
"(",
"xml",
")",
"@server",
"=",
"Server",
".",
"new",
"(",
"@hash",
"[",
"\"monit\"",
"]",
"[",
"\"server\"",
"]",
")",
"@platform",
"=",
"Platform",
".",
"new",
"(",
"@hash",
"[",
"\"monit\"",
"]",
"[",
"\"platform\"",
"]",
")",
"options",
"=",
"{",
":host",
"=>",
"@host",
",",
":port",
"=>",
"@port",
",",
":ssl",
"=>",
"@ssl",
",",
":auth",
"=>",
"@auth",
",",
":username",
"=>",
"@username",
",",
":password",
"=>",
"@password",
"}",
"if",
"@hash",
"[",
"\"monit\"",
"]",
"[",
"\"service\"",
"]",
".",
"is_a?",
"Array",
"@services",
"=",
"@hash",
"[",
"\"monit\"",
"]",
"[",
"\"service\"",
"]",
".",
"map",
"do",
"|",
"service",
"|",
"Service",
".",
"new",
"(",
"service",
",",
"options",
")",
"end",
"else",
"@services",
"=",
"[",
"Service",
".",
"new",
"(",
"@hash",
"[",
"\"monit\"",
"]",
"[",
"\"service\"",
"]",
",",
"options",
")",
"]",
"end",
"true",
"rescue",
"false",
"end"
]
| Parse the XML from Monit into a hash and into a Ruby representation. | [
"Parse",
"the",
"XML",
"from",
"Monit",
"into",
"a",
"hash",
"and",
"into",
"a",
"Ruby",
"representation",
"."
]
| ace938155259e269e4ba492bec6e24502d33a8cf | https://github.com/matiaskorhonen/monit/blob/ace938155259e269e4ba492bec6e24502d33a8cf/lib/monit/status.rb#L78-L102 | train |
berkshelf/solve | lib/solve/graph.rb | Solve.Graph.artifact | def artifact(name, version)
unless artifact?(name, version)
artifact = Artifact.new(self, name, version)
@artifacts["#{name}-#{version}"] = artifact
@artifacts_by_name[name] << artifact
end
@artifacts["#{name}-#{version}"]
end | ruby | def artifact(name, version)
unless artifact?(name, version)
artifact = Artifact.new(self, name, version)
@artifacts["#{name}-#{version}"] = artifact
@artifacts_by_name[name] << artifact
end
@artifacts["#{name}-#{version}"]
end | [
"def",
"artifact",
"(",
"name",
",",
"version",
")",
"unless",
"artifact?",
"(",
"name",
",",
"version",
")",
"artifact",
"=",
"Artifact",
".",
"new",
"(",
"self",
",",
"name",
",",
"version",
")",
"@artifacts",
"[",
"\"#{name}-#{version}\"",
"]",
"=",
"artifact",
"@artifacts_by_name",
"[",
"name",
"]",
"<<",
"artifact",
"end",
"@artifacts",
"[",
"\"#{name}-#{version}\"",
"]",
"end"
]
| Add an artifact to the graph
@param [String] name
@Param [String] version | [
"Add",
"an",
"artifact",
"to",
"the",
"graph"
]
| a0e03ede13e2f66b8dd6d0d34c9c9db70fba94d2 | https://github.com/berkshelf/solve/blob/a0e03ede13e2f66b8dd6d0d34c9c9db70fba94d2/lib/solve/graph.rb#L28-L36 | train |
berkshelf/solve | lib/solve/graph.rb | Solve.Graph.versions | def versions(name, constraint = Semverse::DEFAULT_CONSTRAINT)
constraint = Semverse::Constraint.coerce(constraint)
if constraint == Semverse::DEFAULT_CONSTRAINT
@artifacts_by_name[name]
else
@artifacts_by_name[name].select do |artifact|
constraint.satisfies?(artifact.version)
end
end
end | ruby | def versions(name, constraint = Semverse::DEFAULT_CONSTRAINT)
constraint = Semverse::Constraint.coerce(constraint)
if constraint == Semverse::DEFAULT_CONSTRAINT
@artifacts_by_name[name]
else
@artifacts_by_name[name].select do |artifact|
constraint.satisfies?(artifact.version)
end
end
end | [
"def",
"versions",
"(",
"name",
",",
"constraint",
"=",
"Semverse",
"::",
"DEFAULT_CONSTRAINT",
")",
"constraint",
"=",
"Semverse",
"::",
"Constraint",
".",
"coerce",
"(",
"constraint",
")",
"if",
"constraint",
"==",
"Semverse",
"::",
"DEFAULT_CONSTRAINT",
"@artifacts_by_name",
"[",
"name",
"]",
"else",
"@artifacts_by_name",
"[",
"name",
"]",
".",
"select",
"do",
"|",
"artifact",
"|",
"constraint",
".",
"satisfies?",
"(",
"artifact",
".",
"version",
")",
"end",
"end",
"end"
]
| Return all the artifacts from the collection of artifacts
with the given name.
@param [String] name
@return [Array<Solve::Artifact>] | [
"Return",
"all",
"the",
"artifacts",
"from",
"the",
"collection",
"of",
"artifacts",
"with",
"the",
"given",
"name",
"."
]
| a0e03ede13e2f66b8dd6d0d34c9c9db70fba94d2 | https://github.com/berkshelf/solve/blob/a0e03ede13e2f66b8dd6d0d34c9c9db70fba94d2/lib/solve/graph.rb#L51-L61 | train |
berkshelf/solve | lib/solve/constraint.rb | Solve.Constraint.satisfies? | def satisfies?(target)
target = Semverse::Version.coerce(target)
return false if !(version == 0) && greedy_match?(target)
compare(target)
end | ruby | def satisfies?(target)
target = Semverse::Version.coerce(target)
return false if !(version == 0) && greedy_match?(target)
compare(target)
end | [
"def",
"satisfies?",
"(",
"target",
")",
"target",
"=",
"Semverse",
"::",
"Version",
".",
"coerce",
"(",
"target",
")",
"return",
"false",
"if",
"!",
"(",
"version",
"==",
"0",
")",
"&&",
"greedy_match?",
"(",
"target",
")",
"compare",
"(",
"target",
")",
"end"
]
| Returns true or false if the given version would be satisfied by
the version constraint.
@param [Semverse::Version, #to_s] target
@return [Boolean] | [
"Returns",
"true",
"or",
"false",
"if",
"the",
"given",
"version",
"would",
"be",
"satisfied",
"by",
"the",
"version",
"constraint",
"."
]
| a0e03ede13e2f66b8dd6d0d34c9c9db70fba94d2 | https://github.com/berkshelf/solve/blob/a0e03ede13e2f66b8dd6d0d34c9c9db70fba94d2/lib/solve/constraint.rb#L201-L207 | train |
berkshelf/solve | lib/solve/gecode_solver.rb | Solve.GecodeSolver.solve_demands | def solve_demands(demands_as_constraints)
selector = DepSelector::Selector.new(ds_graph, (timeout_ms / 1000.0))
selector.find_solution(demands_as_constraints, all_artifacts)
rescue DepSelector::Exceptions::InvalidSolutionConstraints => e
report_invalid_constraints_error(e)
rescue DepSelector::Exceptions::NoSolutionExists => e
report_no_solution_error(e)
rescue DepSelector::Exceptions::TimeBoundExceeded
# DepSelector timed out trying to find the solution. There may or may
# not be a solution.
raise Solve::Errors::NoSolutionError.new(
"The dependency constraints could not be solved in the time allotted.")
rescue DepSelector::Exceptions::TimeBoundExceededNoSolution
# DepSelector determined there wasn't a solution to the problem, then
# timed out trying to determine which constraints cause the conflict.
raise Solve::Errors::NoSolutionCauseUnknown.new(
"There is a dependency conflict, but the solver could not determine the precise cause in the time allotted.")
end | ruby | def solve_demands(demands_as_constraints)
selector = DepSelector::Selector.new(ds_graph, (timeout_ms / 1000.0))
selector.find_solution(demands_as_constraints, all_artifacts)
rescue DepSelector::Exceptions::InvalidSolutionConstraints => e
report_invalid_constraints_error(e)
rescue DepSelector::Exceptions::NoSolutionExists => e
report_no_solution_error(e)
rescue DepSelector::Exceptions::TimeBoundExceeded
# DepSelector timed out trying to find the solution. There may or may
# not be a solution.
raise Solve::Errors::NoSolutionError.new(
"The dependency constraints could not be solved in the time allotted.")
rescue DepSelector::Exceptions::TimeBoundExceededNoSolution
# DepSelector determined there wasn't a solution to the problem, then
# timed out trying to determine which constraints cause the conflict.
raise Solve::Errors::NoSolutionCauseUnknown.new(
"There is a dependency conflict, but the solver could not determine the precise cause in the time allotted.")
end | [
"def",
"solve_demands",
"(",
"demands_as_constraints",
")",
"selector",
"=",
"DepSelector",
"::",
"Selector",
".",
"new",
"(",
"ds_graph",
",",
"(",
"timeout_ms",
"/",
"1000.0",
")",
")",
"selector",
".",
"find_solution",
"(",
"demands_as_constraints",
",",
"all_artifacts",
")",
"rescue",
"DepSelector",
"::",
"Exceptions",
"::",
"InvalidSolutionConstraints",
"=>",
"e",
"report_invalid_constraints_error",
"(",
"e",
")",
"rescue",
"DepSelector",
"::",
"Exceptions",
"::",
"NoSolutionExists",
"=>",
"e",
"report_no_solution_error",
"(",
"e",
")",
"rescue",
"DepSelector",
"::",
"Exceptions",
"::",
"TimeBoundExceeded",
"raise",
"Solve",
"::",
"Errors",
"::",
"NoSolutionError",
".",
"new",
"(",
"\"The dependency constraints could not be solved in the time allotted.\"",
")",
"rescue",
"DepSelector",
"::",
"Exceptions",
"::",
"TimeBoundExceededNoSolution",
"raise",
"Solve",
"::",
"Errors",
"::",
"NoSolutionCauseUnknown",
".",
"new",
"(",
"\"There is a dependency conflict, but the solver could not determine the precise cause in the time allotted.\"",
")",
"end"
]
| Runs the solver with the set of demands given. If any DepSelector
exceptions are raised, they are rescued and re-raised | [
"Runs",
"the",
"solver",
"with",
"the",
"set",
"of",
"demands",
"given",
".",
"If",
"any",
"DepSelector",
"exceptions",
"are",
"raised",
"they",
"are",
"rescued",
"and",
"re",
"-",
"raised"
]
| a0e03ede13e2f66b8dd6d0d34c9c9db70fba94d2 | https://github.com/berkshelf/solve/blob/a0e03ede13e2f66b8dd6d0d34c9c9db70fba94d2/lib/solve/gecode_solver.rb#L94-L111 | train |
berkshelf/solve | lib/solve/ruby_solver.rb | Solve.RubySolver.requirement_satisfied_by? | def requirement_satisfied_by?(requirement, activated, spec)
version = spec.version
return false unless requirement.constraint.satisfies?(version)
shared_possibility_versions = possibility_versions(requirement, activated)
return false if !shared_possibility_versions.empty? && !shared_possibility_versions.include?(version)
true
end | ruby | def requirement_satisfied_by?(requirement, activated, spec)
version = spec.version
return false unless requirement.constraint.satisfies?(version)
shared_possibility_versions = possibility_versions(requirement, activated)
return false if !shared_possibility_versions.empty? && !shared_possibility_versions.include?(version)
true
end | [
"def",
"requirement_satisfied_by?",
"(",
"requirement",
",",
"activated",
",",
"spec",
")",
"version",
"=",
"spec",
".",
"version",
"return",
"false",
"unless",
"requirement",
".",
"constraint",
".",
"satisfies?",
"(",
"version",
")",
"shared_possibility_versions",
"=",
"possibility_versions",
"(",
"requirement",
",",
"activated",
")",
"return",
"false",
"if",
"!",
"shared_possibility_versions",
".",
"empty?",
"&&",
"!",
"shared_possibility_versions",
".",
"include?",
"(",
"version",
")",
"true",
"end"
]
| Callback required by Molinillo
Determines whether the given `requirement` is satisfied by the given
`spec`, in the context of the current `activated` dependency graph.
@param [Object] requirement
@param [DependencyGraph] activated the current dependency graph in the
resolution process.
@param [Object] spec
@return [Boolean] whether `requirement` is satisfied by `spec` in the
context of the current `activated` dependency graph. | [
"Callback",
"required",
"by",
"Molinillo",
"Determines",
"whether",
"the",
"given",
"requirement",
"is",
"satisfied",
"by",
"the",
"given",
"spec",
"in",
"the",
"context",
"of",
"the",
"current",
"activated",
"dependency",
"graph",
"."
]
| a0e03ede13e2f66b8dd6d0d34c9c9db70fba94d2 | https://github.com/berkshelf/solve/blob/a0e03ede13e2f66b8dd6d0d34c9c9db70fba94d2/lib/solve/ruby_solver.rb#L171-L177 | train |
berkshelf/solve | lib/solve/ruby_solver.rb | Solve.RubySolver.possibility_versions | def possibility_versions(requirement, activated)
activated.vertices.values.flat_map do |vertex|
next unless vertex.payload
next unless vertex.name == requirement.name
if vertex.payload.respond_to?(:possibilities)
vertex.payload.possibilities.map(&:version)
else
vertex.payload.version
end
end.compact
end | ruby | def possibility_versions(requirement, activated)
activated.vertices.values.flat_map do |vertex|
next unless vertex.payload
next unless vertex.name == requirement.name
if vertex.payload.respond_to?(:possibilities)
vertex.payload.possibilities.map(&:version)
else
vertex.payload.version
end
end.compact
end | [
"def",
"possibility_versions",
"(",
"requirement",
",",
"activated",
")",
"activated",
".",
"vertices",
".",
"values",
".",
"flat_map",
"do",
"|",
"vertex",
"|",
"next",
"unless",
"vertex",
".",
"payload",
"next",
"unless",
"vertex",
".",
"name",
"==",
"requirement",
".",
"name",
"if",
"vertex",
".",
"payload",
".",
"respond_to?",
"(",
":possibilities",
")",
"vertex",
".",
"payload",
".",
"possibilities",
".",
"map",
"(",
"&",
":version",
")",
"else",
"vertex",
".",
"payload",
".",
"version",
"end",
"end",
".",
"compact",
"end"
]
| Searches the current dependency graph to find previously activated
requirements for the current artifact.
@param [Object] requirement
@param [DependencyGraph] activated the current dependency graph in the
resolution process.
@return [Array<Semverse::Version> the list of currently activated versions
of this requirement | [
"Searches",
"the",
"current",
"dependency",
"graph",
"to",
"find",
"previously",
"activated",
"requirements",
"for",
"the",
"current",
"artifact",
"."
]
| a0e03ede13e2f66b8dd6d0d34c9c9db70fba94d2 | https://github.com/berkshelf/solve/blob/a0e03ede13e2f66b8dd6d0d34c9c9db70fba94d2/lib/solve/ruby_solver.rb#L187-L200 | train |
jwhitehorn/pi_piper | lib/pi_piper/spi.rb | PiPiper.Spi.clock | def clock(frequency)
options = {4000 => 0, #4 kHz
8000 => 32768, #8 kHz
15625 => 16384, #15.625 kHz
31250 => 8192, #31.25 kHz
62500 => 4096, #62.5 kHz
125000 => 2048, #125 kHz
250000 => 1024, #250 kHz
500000 => 512, #500 kHz
1000000 => 256, #1 MHz
2000000 => 128, #2 MHz
4000000 => 64, #4 MHz
8000000 => 32, #8 MHz
20000000 => 16 #20 MHz
}
divider = options[frequency]
PiPiper.driver.spi_clock(divider)
end | ruby | def clock(frequency)
options = {4000 => 0, #4 kHz
8000 => 32768, #8 kHz
15625 => 16384, #15.625 kHz
31250 => 8192, #31.25 kHz
62500 => 4096, #62.5 kHz
125000 => 2048, #125 kHz
250000 => 1024, #250 kHz
500000 => 512, #500 kHz
1000000 => 256, #1 MHz
2000000 => 128, #2 MHz
4000000 => 64, #4 MHz
8000000 => 32, #8 MHz
20000000 => 16 #20 MHz
}
divider = options[frequency]
PiPiper.driver.spi_clock(divider)
end | [
"def",
"clock",
"(",
"frequency",
")",
"options",
"=",
"{",
"4000",
"=>",
"0",
",",
"8000",
"=>",
"32768",
",",
"15625",
"=>",
"16384",
",",
"31250",
"=>",
"8192",
",",
"62500",
"=>",
"4096",
",",
"125000",
"=>",
"2048",
",",
"250000",
"=>",
"1024",
",",
"500000",
"=>",
"512",
",",
"1000000",
"=>",
"256",
",",
"2000000",
"=>",
"128",
",",
"4000000",
"=>",
"64",
",",
"8000000",
"=>",
"32",
",",
"20000000",
"=>",
"16",
"}",
"divider",
"=",
"options",
"[",
"frequency",
"]",
"PiPiper",
".",
"driver",
".",
"spi_clock",
"(",
"divider",
")",
"end"
]
| Sets the SPI clock frequency | [
"Sets",
"the",
"SPI",
"clock",
"frequency"
]
| bf17c88c8d27f87baf04868482b8082b6a8390ea | https://github.com/jwhitehorn/pi_piper/blob/bf17c88c8d27f87baf04868482b8082b6a8390ea/lib/pi_piper/spi.rb#L64-L81 | train |
jwhitehorn/pi_piper | lib/pi_piper/spi.rb | PiPiper.Spi.chip_select | def chip_select(chip=CHIP_SELECT_0)
chip = @chip if @chip
PiPiper.driver.spi_chip_select(chip)
if block_given?
begin
yield
ensure
PiPiper.driver.spi_chip_select(CHIP_SELECT_NONE)
end
end
end | ruby | def chip_select(chip=CHIP_SELECT_0)
chip = @chip if @chip
PiPiper.driver.spi_chip_select(chip)
if block_given?
begin
yield
ensure
PiPiper.driver.spi_chip_select(CHIP_SELECT_NONE)
end
end
end | [
"def",
"chip_select",
"(",
"chip",
"=",
"CHIP_SELECT_0",
")",
"chip",
"=",
"@chip",
"if",
"@chip",
"PiPiper",
".",
"driver",
".",
"spi_chip_select",
"(",
"chip",
")",
"if",
"block_given?",
"begin",
"yield",
"ensure",
"PiPiper",
".",
"driver",
".",
"spi_chip_select",
"(",
"CHIP_SELECT_NONE",
")",
"end",
"end",
"end"
]
| Activate a specific chip so that communication can begin
When a block is provided, the chip is automatically deactivated after the block completes.
When a block is not provided, the user is responsible for calling chip_select(CHIP_SELECT_NONE)
@example With block (preferred)
spi.chip_select do
spi.write(0xFF)
end
@example Without block
spi.chip_select(CHIP_SELECT_0)
spi.write(0xFF)
spi.write(0x22)
spi.chip_select(CHIP_SELECT_NONE)
@yield
@param [optional, CHIP_SELECT_*] chip the chip select line options | [
"Activate",
"a",
"specific",
"chip",
"so",
"that",
"communication",
"can",
"begin"
]
| bf17c88c8d27f87baf04868482b8082b6a8390ea | https://github.com/jwhitehorn/pi_piper/blob/bf17c88c8d27f87baf04868482b8082b6a8390ea/lib/pi_piper/spi.rb#L113-L123 | train |
jwhitehorn/pi_piper | lib/pi_piper/spi.rb | PiPiper.Spi.chip_select_active_low | def chip_select_active_low(active_low, chip=nil)
chip = @chip if @chip
chip = CHIP_SELECT_0 unless chip
PiPiper.driver.spi_chip_select_polarity(chip, active_low ? 0 : 1)
end | ruby | def chip_select_active_low(active_low, chip=nil)
chip = @chip if @chip
chip = CHIP_SELECT_0 unless chip
PiPiper.driver.spi_chip_select_polarity(chip, active_low ? 0 : 1)
end | [
"def",
"chip_select_active_low",
"(",
"active_low",
",",
"chip",
"=",
"nil",
")",
"chip",
"=",
"@chip",
"if",
"@chip",
"chip",
"=",
"CHIP_SELECT_0",
"unless",
"chip",
"PiPiper",
".",
"driver",
".",
"spi_chip_select_polarity",
"(",
"chip",
",",
"active_low",
"?",
"0",
":",
"1",
")",
"end"
]
| Configure the active state of the chip select line
The default state for most chips is active low.
"active low" means the clock line is kept high during idle, and goes low when communicating.
"active high" means the clock line is kept low during idle, and goes high when communicating.
@param [Boolean] active_low true for active low, false for active high
@param [optional, CHIP_SELECT_*] chip one of CHIP_SELECT_* | [
"Configure",
"the",
"active",
"state",
"of",
"the",
"chip",
"select",
"line"
]
| bf17c88c8d27f87baf04868482b8082b6a8390ea | https://github.com/jwhitehorn/pi_piper/blob/bf17c88c8d27f87baf04868482b8082b6a8390ea/lib/pi_piper/spi.rb#L135-L140 | train |
jwhitehorn/pi_piper | lib/pi_piper/spi.rb | PiPiper.Spi.write | def write(*args)
case args.count
when 0
raise ArgumentError, "missing arguments"
when 1
data = args.first
else
data = args
end
enable do
case data
when Numeric
PiPiper.driver.spi_transfer(data)
when Enumerable
PiPiper.driver.spi_transfer_bytes(data)
else
raise ArgumentError, "#{data.class} is not valid data. Use Numeric or an Enumerable of numbers"
end
end
end | ruby | def write(*args)
case args.count
when 0
raise ArgumentError, "missing arguments"
when 1
data = args.first
else
data = args
end
enable do
case data
when Numeric
PiPiper.driver.spi_transfer(data)
when Enumerable
PiPiper.driver.spi_transfer_bytes(data)
else
raise ArgumentError, "#{data.class} is not valid data. Use Numeric or an Enumerable of numbers"
end
end
end | [
"def",
"write",
"(",
"*",
"args",
")",
"case",
"args",
".",
"count",
"when",
"0",
"raise",
"ArgumentError",
",",
"\"missing arguments\"",
"when",
"1",
"data",
"=",
"args",
".",
"first",
"else",
"data",
"=",
"args",
"end",
"enable",
"do",
"case",
"data",
"when",
"Numeric",
"PiPiper",
".",
"driver",
".",
"spi_transfer",
"(",
"data",
")",
"when",
"Enumerable",
"PiPiper",
".",
"driver",
".",
"spi_transfer_bytes",
"(",
"data",
")",
"else",
"raise",
"ArgumentError",
",",
"\"#{data.class} is not valid data. Use Numeric or an Enumerable of numbers\"",
"end",
"end",
"end"
]
| Write to the bus
@example Write a single byte
spi.write(0x22)
@example Write multiple bytes
spi.write(0x22, 0x33, 0x44)
@return [Number|Array] data that came out of MISO during write | [
"Write",
"to",
"the",
"bus"
]
| bf17c88c8d27f87baf04868482b8082b6a8390ea | https://github.com/jwhitehorn/pi_piper/blob/bf17c88c8d27f87baf04868482b8082b6a8390ea/lib/pi_piper/spi.rb#L172-L192 | train |
infinitered/rmq | motion/ruby_motion_query/subviews.rb | RubyMotionQuery.RMQ.add_subview | def add_subview(view_or_constant, opts={})
subviews_added = []
selected.each do |selected_view|
created = false
appended = false
built = false
if view_or_constant.is_a?(UIView)
new_view = view_or_constant
else
created = true
new_view = create_view(view_or_constant, opts)
end
rmq_data = new_view.rmq_data
unless rmq_data.built
rmq_data.built = true # build only once
built = true
end
rmq_data.view_controller = self.weak_view_controller
subviews_added << new_view
unless opts[:do_not_add]
if at_index = opts[:at_index]
selected_view.insertSubview(new_view, atIndex: at_index)
elsif below_view = opts[:below_view]
selected_view.insertSubview(new_view, belowSubview: below_view)
else
selected_view.addSubview(new_view)
end
appended = true
end
if created
new_view.rmq_created
end
new_view.rmq_build if built
new_view.rmq_appended if appended
if self.stylesheet
apply_style_to_view(new_view, opts[:style]) if opts[:style]
end
end
view = RMQ.create_with_array_and_selectors(subviews_added, selectors, @context, self)
opts[:block].call view if opts[:block]
opts[:raw_block].call view.get if opts[:raw_block]
view
end | ruby | def add_subview(view_or_constant, opts={})
subviews_added = []
selected.each do |selected_view|
created = false
appended = false
built = false
if view_or_constant.is_a?(UIView)
new_view = view_or_constant
else
created = true
new_view = create_view(view_or_constant, opts)
end
rmq_data = new_view.rmq_data
unless rmq_data.built
rmq_data.built = true # build only once
built = true
end
rmq_data.view_controller = self.weak_view_controller
subviews_added << new_view
unless opts[:do_not_add]
if at_index = opts[:at_index]
selected_view.insertSubview(new_view, atIndex: at_index)
elsif below_view = opts[:below_view]
selected_view.insertSubview(new_view, belowSubview: below_view)
else
selected_view.addSubview(new_view)
end
appended = true
end
if created
new_view.rmq_created
end
new_view.rmq_build if built
new_view.rmq_appended if appended
if self.stylesheet
apply_style_to_view(new_view, opts[:style]) if opts[:style]
end
end
view = RMQ.create_with_array_and_selectors(subviews_added, selectors, @context, self)
opts[:block].call view if opts[:block]
opts[:raw_block].call view.get if opts[:raw_block]
view
end | [
"def",
"add_subview",
"(",
"view_or_constant",
",",
"opts",
"=",
"{",
"}",
")",
"subviews_added",
"=",
"[",
"]",
"selected",
".",
"each",
"do",
"|",
"selected_view",
"|",
"created",
"=",
"false",
"appended",
"=",
"false",
"built",
"=",
"false",
"if",
"view_or_constant",
".",
"is_a?",
"(",
"UIView",
")",
"new_view",
"=",
"view_or_constant",
"else",
"created",
"=",
"true",
"new_view",
"=",
"create_view",
"(",
"view_or_constant",
",",
"opts",
")",
"end",
"rmq_data",
"=",
"new_view",
".",
"rmq_data",
"unless",
"rmq_data",
".",
"built",
"rmq_data",
".",
"built",
"=",
"true",
"built",
"=",
"true",
"end",
"rmq_data",
".",
"view_controller",
"=",
"self",
".",
"weak_view_controller",
"subviews_added",
"<<",
"new_view",
"unless",
"opts",
"[",
":do_not_add",
"]",
"if",
"at_index",
"=",
"opts",
"[",
":at_index",
"]",
"selected_view",
".",
"insertSubview",
"(",
"new_view",
",",
"atIndex",
":",
"at_index",
")",
"elsif",
"below_view",
"=",
"opts",
"[",
":below_view",
"]",
"selected_view",
".",
"insertSubview",
"(",
"new_view",
",",
"belowSubview",
":",
"below_view",
")",
"else",
"selected_view",
".",
"addSubview",
"(",
"new_view",
")",
"end",
"appended",
"=",
"true",
"end",
"if",
"created",
"new_view",
".",
"rmq_created",
"end",
"new_view",
".",
"rmq_build",
"if",
"built",
"new_view",
".",
"rmq_appended",
"if",
"appended",
"if",
"self",
".",
"stylesheet",
"apply_style_to_view",
"(",
"new_view",
",",
"opts",
"[",
":style",
"]",
")",
"if",
"opts",
"[",
":style",
"]",
"end",
"end",
"view",
"=",
"RMQ",
".",
"create_with_array_and_selectors",
"(",
"subviews_added",
",",
"selectors",
",",
"@context",
",",
"self",
")",
"opts",
"[",
":block",
"]",
".",
"call",
"view",
"if",
"opts",
"[",
":block",
"]",
"opts",
"[",
":raw_block",
"]",
".",
"call",
"view",
".",
"get",
"if",
"opts",
"[",
":raw_block",
"]",
"view",
"end"
]
| This is used by build, create, and append. You really shouldn't use it
directly. Although it's totally fine if you do
@return [RMQ] | [
"This",
"is",
"used",
"by",
"build",
"create",
"and",
"append",
".",
"You",
"really",
"shouldn",
"t",
"use",
"it",
"directly",
".",
"Although",
"it",
"s",
"totally",
"fine",
"if",
"you",
"do"
]
| a8329e1574ce3275c9fe56b91127c8b5e4b7693e | https://github.com/infinitered/rmq/blob/a8329e1574ce3275c9fe56b91127c8b5e4b7693e/motion/ruby_motion_query/subviews.rb#L20-L73 | train |
infinitered/rmq | motion/ruby_motion_query/subviews.rb | RubyMotionQuery.RMQ.find_or_append | def find_or_append(view_or_constant, style=nil, opts = {}, &block)
if style && (q = self.find(style)) && q.length > 0
view_or_constant = q.get
end
append(view_or_constant, style, opts, &block)
end | ruby | def find_or_append(view_or_constant, style=nil, opts = {}, &block)
if style && (q = self.find(style)) && q.length > 0
view_or_constant = q.get
end
append(view_or_constant, style, opts, &block)
end | [
"def",
"find_or_append",
"(",
"view_or_constant",
",",
"style",
"=",
"nil",
",",
"opts",
"=",
"{",
"}",
",",
"&",
"block",
")",
"if",
"style",
"&&",
"(",
"q",
"=",
"self",
".",
"find",
"(",
"style",
")",
")",
"&&",
"q",
".",
"length",
">",
"0",
"view_or_constant",
"=",
"q",
".",
"get",
"end",
"append",
"(",
"view_or_constant",
",",
"style",
",",
"opts",
",",
"&",
"block",
")",
"end"
]
| Same as append, but will look for a view with the same name and reapply styles
to it if it finds one. If it doesn't, it'll append as normal.
@example
@my_button = rmq.find_or_append(UIButton, :my_button)
@my_button = rmq.find_or_append(UIButton, :my_button) # Only one created | [
"Same",
"as",
"append",
"but",
"will",
"look",
"for",
"a",
"view",
"with",
"the",
"same",
"name",
"and",
"reapply",
"styles",
"to",
"it",
"if",
"it",
"finds",
"one",
".",
"If",
"it",
"doesn",
"t",
"it",
"ll",
"append",
"as",
"normal",
"."
]
| a8329e1574ce3275c9fe56b91127c8b5e4b7693e | https://github.com/infinitered/rmq/blob/a8329e1574ce3275c9fe56b91127c8b5e4b7693e/motion/ruby_motion_query/subviews.rb#L120-L126 | train |
infinitered/rmq | motion/ruby_motion_query/subviews.rb | RubyMotionQuery.RMQ.find_or_append! | def find_or_append!(view_or_constant, style=nil, opts = {}, &block)
find_or_append(view_or_constant, style, opts, &block).get
end | ruby | def find_or_append!(view_or_constant, style=nil, opts = {}, &block)
find_or_append(view_or_constant, style, opts, &block).get
end | [
"def",
"find_or_append!",
"(",
"view_or_constant",
",",
"style",
"=",
"nil",
",",
"opts",
"=",
"{",
"}",
",",
"&",
"block",
")",
"find_or_append",
"(",
"view_or_constant",
",",
"style",
",",
"opts",
",",
"&",
"block",
")",
".",
"get",
"end"
]
| Same as append!, but will look for a view with the same name and reapply styles
to it if it finds one. If it doesn't, it'll append! as normal.
@example
@my_button = rmq.find_or_append!(UIButton, :my_button)
@my_button = rmq.find_or_append!(UIButton, :my_button) # Only one created | [
"Same",
"as",
"append!",
"but",
"will",
"look",
"for",
"a",
"view",
"with",
"the",
"same",
"name",
"and",
"reapply",
"styles",
"to",
"it",
"if",
"it",
"finds",
"one",
".",
"If",
"it",
"doesn",
"t",
"it",
"ll",
"append!",
"as",
"normal",
"."
]
| a8329e1574ce3275c9fe56b91127c8b5e4b7693e | https://github.com/infinitered/rmq/blob/a8329e1574ce3275c9fe56b91127c8b5e4b7693e/motion/ruby_motion_query/subviews.rb#L134-L136 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.