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
-
#cancel ⇒ Object
There are two courses of action here:.
- #cancelled? ⇒ Boolean
- #cancelling? ⇒ Boolean
-
#complete? ⇒ Boolean
This is used as a catch-all for finished, cancelled, failed, job_failed? and timeout.
- #failed? ⇒ Boolean
- #finished? ⇒ Boolean
- #has_parent? ⇒ Boolean
-
#incomplete? ⇒ Boolean
This is used as a catch-all for pending?, initialized? and running?.
- #initialized? ⇒ Boolean
- #job_failed? ⇒ Boolean
- #pending? ⇒ Boolean
-
#root_ancestor ⇒ Object
Get the original ancestor of this run.
- #running? ⇒ Boolean
-
#state ⇒ Object
Return state as a symbol.
-
#state=(state) ⇒ Object
Save state as a downcased string.
- #status_message ⇒ Object
- #timeout? ⇒ Boolean
Instance Method Details
#cancel ⇒ Object
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. = "cancelled" end end end save end |
#cancelled? ⇒ Boolean
211 212 213 |
# File 'lib/taverna_player/concerns/models/run.rb', line 211 def cancelled? state == :cancelled end |
#cancelling? ⇒ 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
238 239 240 |
# File 'lib/taverna_player/concerns/models/run.rb', line 238 def complete? finished? || cancelled? || failed? || job_failed? || timeout? end |
#failed? ⇒ Boolean
223 224 225 |
# File 'lib/taverna_player/concerns/models/run.rb', line 223 def failed? state == :failed end |
#finished? ⇒ Boolean
207 208 209 |
# File 'lib/taverna_player/concerns/models/run.rb', line 207 def finished? state == :finished end |
#has_parent? ⇒ 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?
232 233 234 |
# File 'lib/taverna_player/concerns/models/run.rb', line 232 def incomplete? running? || pending? || initialized? end |
#initialized? ⇒ Boolean
199 200 201 |
# File 'lib/taverna_player/concerns/models/run.rb', line 199 def initialized? state == :initialized end |
#job_failed? ⇒ 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
195 196 197 |
# File 'lib/taverna_player/concerns/models/run.rb', line 195 def pending? state == :pending end |
#root_ancestor ⇒ Object
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
203 204 205 |
# File 'lib/taverna_player/concerns/models/run.rb', line 203 def running? state == :running end |
#state ⇒ Object
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_message ⇒ Object
190 191 192 193 |
# File 'lib/taverna_player/concerns/models/run.rb', line 190 def key = .nil? ? saved_state : I18n.t("taverna_player.status.#{key}") end |
#timeout? ⇒ Boolean
219 220 221 |
# File 'lib/taverna_player/concerns/models/run.rb', line 219 def timeout? state == :timeout end |