Module: TavernaPlayer::Concerns::Models::Run

Extended by:
ActiveSupport::Concern
Included in:
Run
Defined in:
lib/taverna_player/concerns/models/run.rb

Instance Method Summary collapse

Instance Method Details

#cancelObject

There are two courses of action here:

  • If the run is already running then cancel this run by setting the stop flag. This is done to allow the delayed job that is monitoring the run to delete it and clean up Taverna Server gracefully.

  • If the run is still in the queue, destroy the queue object. This is checked in a transaction so that we don’t get hit with a race condition between checking the queued status of the run and actually removing it from the queue.

In both cases the stop flag is set to mark the run as cancelled internally.

See the note above about the :cancelled state.



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/taverna_player/concerns/models/run.rb', line 147

def cancel
  return unless incomplete?

  # Set the stop flag for all cases.
  self.stop = true

  # If the run has a delayed job and it hasn't been locked yet, or it
  # has failed, then we just remove it from the queue directly and
  # mark the run as cancelled.
  unless delayed_job.nil?
    delayed_job.with_lock do
      if delayed_job.locked_by.nil? || !delayed_job.failed_at.nil?
        delayed_job.destroy
        self.state = :cancelled
        self.status_message_key = "cancelled"
      end
    end
  end

  save
end

#cancelled?Boolean

Returns:

  • (Boolean)


211
212
213
# File 'lib/taverna_player/concerns/models/run.rb', line 211

def cancelled?
  state == :cancelled
end

#cancelling?Boolean

Returns:

  • (Boolean)


215
216
217
# File 'lib/taverna_player/concerns/models/run.rb', line 215

def cancelling?
  state == :cancelling
end

#complete?Boolean

This is used as a catch-all for finished, cancelled, failed, job_failed? and timeout

Returns:

  • (Boolean)


238
239
240
# File 'lib/taverna_player/concerns/models/run.rb', line 238

def complete?
  finished? || cancelled? || failed? || job_failed? || timeout?
end

#failed?Boolean

Returns:

  • (Boolean)


223
224
225
# File 'lib/taverna_player/concerns/models/run.rb', line 223

def failed?
  state == :failed
end

#finished?Boolean

Returns:

  • (Boolean)


207
208
209
# File 'lib/taverna_player/concerns/models/run.rb', line 207

def finished?
  state == :finished
end

#has_parent?Boolean

Returns:

  • (Boolean)


242
243
244
# File 'lib/taverna_player/concerns/models/run.rb', line 242

def has_parent?
  !parent_id.nil?
end

#incomplete?Boolean

This is used as a catch-all for pending?, initialized? and running?

Returns:

  • (Boolean)


232
233
234
# File 'lib/taverna_player/concerns/models/run.rb', line 232

def incomplete?
  running? || pending? || initialized?
end

#initialized?Boolean

Returns:

  • (Boolean)


199
200
201
# File 'lib/taverna_player/concerns/models/run.rb', line 199

def initialized?
  state == :initialized
end

#job_failed?Boolean

Returns:

  • (Boolean)


227
228
229
# File 'lib/taverna_player/concerns/models/run.rb', line 227

def job_failed?
  !delayed_job.nil? && !delayed_job.failed_at.nil?
end

#pending?Boolean

Returns:

  • (Boolean)


195
196
197
# File 'lib/taverna_player/concerns/models/run.rb', line 195

def pending?
  state == :pending
end

#root_ancestorObject

Get the original ancestor of this run. In practice this is the first run in the chain without a parent.



128
129
130
# File 'lib/taverna_player/concerns/models/run.rb', line 128

def root_ancestor
  has_parent? ? parent.root_ancestor : self
end

#running?Boolean

Returns:

  • (Boolean)


203
204
205
# File 'lib/taverna_player/concerns/models/run.rb', line 203

def running?
  state == :running
end

#stateObject

Return state as a symbol. If a run is running, but has been asked to stop, then it is :cancelling. This is a pseudo-state to avoid race conditions when cancelling a run so is specifically NOT in the list of allowed states above.



173
174
175
176
177
178
179
180
# File 'lib/taverna_player/concerns/models/run.rb', line 173

def state
  s = self[:saved_state].to_sym
  if s == :running
    stop ? :cancelling : :running
  else
    s
  end
end

#state=(state) ⇒ Object

Save state as a downcased string. See the note above about why a state cannot be used to actually cancel a run.



184
185
186
187
188
# File 'lib/taverna_player/concerns/models/run.rb', line 184

def state=(state)
  s = state.to_s.downcase
  return if s == "cancelled" && !stop
  self[:saved_state] = s
end

#status_messageObject



190
191
192
193
# File 'lib/taverna_player/concerns/models/run.rb', line 190

def status_message
  key = status_message_key.nil? ? saved_state : status_message_key
  I18n.t("taverna_player.status.#{key}")
end

#timeout?Boolean

Returns:

  • (Boolean)


219
220
221
# File 'lib/taverna_player/concerns/models/run.rb', line 219

def timeout?
  state == :timeout
end