def launch_single(process_definition, fields={}, variables={}, root_stash=nil)
tree = @context.reader.read(process_definition)
name = tree[1]['name'] || (tree[1].find { |k, v| v.nil? } || []).first
raise ArgumentError.new(
'process definition is missing a name, cannot launch as single'
) unless name
singles = @context.storage.get('variables', 'singles') || {
'_id' => 'singles', 'type' => 'variables', 'h' => {}
}
wfid, timestamp = singles['h'][name]
return wfid if wfid && (ps(wfid) || Time.now.to_f - timestamp < 1.0)
wfid = @context.wfidgen.generate
singles['h'][name] = [ wfid, Time.now.to_f ]
r = @context.storage.put(singles)
return launch_single(tree, fields, variables, root_stash) unless r.nil?
@context.storage.put_msg(
'launch',
'wfid' => wfid,
'tree' => tree,
'workitem' => { 'fields' => fields },
'variables' => variables,
'stash' => root_stash)
wfid
end