Class: WorkflowRESTClient::RemoteStep

Inherits:
Step
  • Object
show all
Defined in:
lib/rbbt/rest/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_url, task = nil, name = nil, inputs = nil, result_type = nil, result_description = nil, exec = false) ⇒ RemoteStep

Returns a new instance of RemoteStep.



96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/rbbt/rest/client.rb', line 96

def initialize(base_url, task = nil, name = nil, inputs = nil, result_type = nil, result_description = nil, exec = false)
  if task.nil?
    @url = base_url
  else
    @base_url, @task, @name, @inputs, @result_type, @result_description = base_url, task, name, inputs, result_type, result_description
    if exec
      @url = [File.join(base_url, task.to_s), inputs]
    else
      self.fork 
    end
  end
end

Instance Attribute Details

#base_urlObject

Returns the value of attribute base_url.



69
70
71
# File 'lib/rbbt/rest/client.rb', line 69

def base_url
  @base_url
end

#inputsObject

Returns the value of attribute inputs.



69
70
71
# File 'lib/rbbt/rest/client.rb', line 69

def inputs
  @inputs
end

#nameObject

Returns the value of attribute name.



69
70
71
# File 'lib/rbbt/rest/client.rb', line 69

def name
  @name
end

#result_descriptionObject

Returns the value of attribute result_description.



69
70
71
# File 'lib/rbbt/rest/client.rb', line 69

def result_description
  @result_description
end

#result_typeObject

Returns the value of attribute result_type.



69
70
71
# File 'lib/rbbt/rest/client.rb', line 69

def result_type
  @result_type
end

#taskObject

Returns the value of attribute task.



69
70
71
# File 'lib/rbbt/rest/client.rb', line 69

def task
  @task
end

#urlObject

Returns the value of attribute url.



69
70
71
# File 'lib/rbbt/rest/client.rb', line 69

def url
  @url
end

Instance Method Details

#_exec(noload = false) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/rbbt/rest/client.rb', line 109

def _exec(noload = false)
  if Array === @url
    url, params = @url
  else
    url, params = @url, {:_cache_type => :synchronous}
  end

  params[:jobname] = @name if @name

  if noload and %w(boolean string tsv).include? result_type
    WorkflowRESTClient.get_raw(url, params) 
  else
    case result_type
    when :string
      WorkflowRESTClient.get_raw(url, params) 
    when :boolean
      WorkflowRESTClient.get_raw(url, params) == "true"
    when :tsv
      TSV.open(StringIO.new(WorkflowRESTClient.get_raw(url, params)))
    when :annotations
      Annotated.load_tsv(TSV.open(StringIO.new(WorkflowRESTClient.get_raw(url, params))))
    else
      WorkflowRESTClient.get_json(url, params)
    end
  end
end

#cleanObject



162
163
164
165
# File 'lib/rbbt/rest/client.rb', line 162

def clean
  WorkflowRESTClient.get_raw(url, :_update => :clean)
  self
end

#done?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/rbbt/rest/client.rb', line 86

def done?
  status.to_s == 'done'
end

#execObject



136
137
138
139
# File 'lib/rbbt/rest/client.rb', line 136

def exec
  res = _exec
  prepare_result(res, result_type)
end

#file(file) ⇒ Object



171
172
173
# File 'lib/rbbt/rest/client.rb', line 171

def file(file)
  WorkflowRESTClient.get_json(File.join(url, 'file', file))
end

#filesObject



167
168
169
# File 'lib/rbbt/rest/client.rb', line 167

def files
  WorkflowRESTClient.get_json(File.join(url, 'files'))
end

#forkObject



90
91
92
93
94
# File 'lib/rbbt/rest/client.rb', line 90

def fork
  @name = WorkflowRESTClient.post_jobname(File.join(base_url, task.to_s), inputs.merge(:jobname => @name, :_cache_type => :asynchronous))
  @url = File.join(base_url, task.to_s, @name)
  self
end

#infoObject



79
80
81
82
83
84
# File 'lib/rbbt/rest/client.rb', line 79

def info
  info = WorkflowRESTClient.get_json(File.join(url, 'info'))
  info = WorkflowRESTClient.fix_hash(info)
  info[:status] = info[:status].to_sym if String === info[:status]
  info
end

#joinObject



153
154
155
156
# File 'lib/rbbt/rest/client.rb', line 153

def join
  exec
  self
end

#loadObject



149
150
151
# File 'lib/rbbt/rest/client.rb', line 149

def load
  exec
end

#run(noload = false) ⇒ Object



141
142
143
144
145
146
147
# File 'lib/rbbt/rest/client.rb', line 141

def run(noload = false)
  if noload
    _exec(noload)
  else
    exec
  end
end

#statusObject



158
159
160
# File 'lib/rbbt/rest/client.rb', line 158

def status
  info[:status]
end

#task_nameObject



75
76
77
# File 'lib/rbbt/rest/client.rb', line 75

def task_name
  (Array === @url ? @url.first : @url).split("/")[-2]
end