Class: WorkflowSOAP

Inherits:
SimpleWS
  • Object
show all
Defined in:
lib/rbbt/workflow/soap.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(workflow, *args) ⇒ WorkflowSOAP

Returns a new instance of WorkflowSOAP.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/rbbt/workflow/soap.rb', line 17

def initialize(workflow, *args)
  super(workflow.to_s, *args)
  @workflow = workflow
  @workflow.synchronous_exports.each do |name| synchronous name end
  @workflow.asynchronous_exports.each do |name| asynchronous name end
  @workflow.stream_exports.each do |name| asynchronous name end

  desc "Job management: Check the status of a job"
  param_desc :jobid => "Job identifier", :return => "Status code. Special status codes are: 'done' and 'error'"
  serve :status, [:jobid], :jobid => :string, :return => :string do |jobid|
    (job(jobid).status || :queued).to_s
  end

  desc "Job management: Return an array with the messages issued by the job"
  param_desc :jobid => "Job identifier", :return => "Array with message strings"
  serve :messages, ['jobid'], :job => :string, :return => :array do |jobid|
    job(jobid).messages || []
  end

  desc "Job management: Return a YAML string containing arbitrary information set up by the job"
  param_desc :jobid => "Job identifier", :return => "Hash with arbitrary values in YAML format"
  serve :info, ['jobid'], :jobid => :string, :return => :string do |jobid|
    job(jobid).info.to_yaml
  end

  desc "Job management: Load job result as string "
  param_desc :jobid => "Job identifier", :return => "String containing the result of the job"
  serve :load_string, %w(jobid), :jobid => :string, :return => :string do |jobid|
    Open.read(job(jobid).path)
  end

  desc "Job management: Abort the job"
  param_desc :jobid => "Job identifier"
  serve :abort, %w(jobid), :jobid => :string, :return => false do |jobid|
    job(jobid).abort
  end

  desc "Job management: Check if the job is done. Could have finished successfully, with error, or have been aborted"
  param_desc :jobid => "Job identifier", :return => "True if the job has status 'done', 'error' or 'aborted'"
  serve :done, %w(jobid), :jobid => :string, :return => :boolean do |jobid|
    [:done, :error, :aborted].include?((job(jobid).status || :queued).to_sym)
  end

  desc "Job management: Check if the job has finished with error. The last message is the error message"
  param_desc :jobid => "Job identifier", :return => "True if the job has status 'error'"
  serve :error, %w(jobid), :jobid => :string, :return => :boolean do |jobid|
    job(jobid).status.to_sym == :error
  end

  desc "Job management: Check if the job has finished with error. The last message is the error message"
  param_desc :jobid => "Job identifier", :return => "True if the job has status 'error'"
  serve :clean, %w(jobid), :jobid => :string, :return => nil do |jobid|
    job(jobid).clean
    nil
  end


end

Instance Attribute Details

#workflowObject

Returns the value of attribute workflow.



5
6
7
# File 'lib/rbbt/workflow/soap.rb', line 5

def workflow
  @workflow
end

Instance Method Details

#asynchronous(*tasknames) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/rbbt/workflow/soap.rb', line 91

def asynchronous(*tasknames)
  tasknames.each do |name|
    task = @workflow.tasks[name]
    desc @workflow.task_description[name] if @workflow.task_description.include? name

    rec_inputs = @workflow.rec_inputs name
    rec_input_descriptions= @workflow.rec_input_descriptions name
    rec_input_types= @workflow.rec_input_types name

    param_desc rec_input_descriptions.merge(:suggested_name => "Suggested Name", :return => "Job identifier")
    serve name, [:suggested_name] + rec_inputs, rec_input_types.merge(:suggested_name => :string, :return => :string) do |jobname, *inputs|
      inputs = Hash[*@workflow.rec_inputs(name).zip(inputs).flatten]
  
      step = @workflow.job(name, jobname, inputs)
      step.fork
      @workflow.id_for step.path
    end
  end
end

#job(jobid) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/rbbt/workflow/soap.rb', line 6

def job(jobid)
  workdir = @workflow.workdir
  if workdir.respond_to? :find
    workdir_find = workdir.find 
  else
    workdir_find = workdir
  end
 
  @workflow.load_step(File.join(workdir_find, jobid))
end

#synchronous(*tasknames) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/rbbt/workflow/soap.rb', line 76

def synchronous(*tasknames)
  tasknames.each do |name|
    name = name.to_sym
    task = @workflow.tasks[name]
    desc @workflow.task_description[name] if @workflow.task_description.include? name

    rec_inputs = @workflow.rec_inputs name
    rec_input_descriptions= @workflow.rec_input_descriptions name
    rec_input_types= @workflow.rec_input_types name

    param_desc rec_input_descriptions
    serve name, rec_inputs, rec_input_types, &task
  end
end