taverna-player 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +8 -8
  2. data/.travis.yml +6 -0
  3. data/CHANGES.rdoc +28 -0
  4. data/CITATION +20 -0
  5. data/Gemfile +0 -12
  6. data/README.rdoc +30 -16
  7. data/Rakefile +1 -0
  8. data/app/controllers/taverna_player/workflows_controller.rb +18 -0
  9. data/app/helpers/taverna_player/application_helper.rb +2 -2
  10. data/app/models/taverna_player/run.rb +35 -3
  11. data/app/models/taverna_player/workflow.rb +41 -0
  12. data/app/views/taverna_player/workflows/_info.json.jbuilder +1 -0
  13. data/{test/dummy/app/views → app/views/taverna_player}/workflows/index.html.erb +1 -1
  14. data/app/views/taverna_player/workflows/index.json.jbuilder +1 -0
  15. data/config/routes.rb +9 -0
  16. data/db/migrate/20140917165505_create_taverna_player_workflows.rb +12 -0
  17. data/lib/generators/taverna_player/controllers_generator.rb +5 -6
  18. data/lib/generators/taverna_player/models_generator.rb +3 -3
  19. data/lib/generators/templates/callbacks/worker_callbacks.rb +5 -5
  20. data/{test/dummy/app → lib/generators/templates}/controllers/workflows_controller.rb +7 -4
  21. data/{test/dummy/test/functional/workflows_controller_test.rb → lib/generators/templates/models/workflow.rb} +6 -7
  22. data/lib/generators/templates/player_initializer.rb +5 -4
  23. data/lib/taverna-player.rb +11 -1
  24. data/lib/taverna_player/concerns/controllers/runs_controller.rb +1 -1
  25. data/lib/taverna_player/concerns/controllers/workflows_controller.rb +41 -0
  26. data/lib/taverna_player/concerns/models/run.rb +42 -14
  27. data/lib/taverna_player/concerns/models/run_port.rb +2 -1
  28. data/lib/taverna_player/concerns/models/workflow.rb +44 -0
  29. data/lib/taverna_player/model_proxy.rb +14 -8
  30. data/lib/taverna_player/version.rb +1 -1
  31. data/taverna_player.gemspec +1 -0
  32. data/test/dummy/app/views/layouts/application.html.erb +1 -1
  33. data/test/dummy/config/initializers/taverna_player.rb +1 -4
  34. data/test/dummy/config/routes.rb +1 -7
  35. data/test/dummy/db/migrate/20140917165846_drop_workflows.rb +9 -0
  36. data/test/dummy/db/migrate/20140917170017_create_taverna_player_workflows.taverna_player.rb +13 -0
  37. data/test/dummy/db/schema.rb +9 -9
  38. data/test/dummy/lib/callbacks.rb +4 -4
  39. data/test/fixtures/delayed_jobs.yml +45 -0
  40. data/test/fixtures/taverna_player/interactions.yml +3 -3
  41. data/test/fixtures/taverna_player/run_ports.yml +7 -12
  42. data/test/fixtures/taverna_player/runs.yml +43 -13
  43. data/test/fixtures/{workflows.yml → taverna_player/workflows.yml} +1 -4
  44. data/test/fixtures/users.yml +2 -3
  45. data/test/functional/taverna_player/runs_controller_test.rb +42 -15
  46. data/test/functional/taverna_player/workflows_controller_test.rb +37 -0
  47. data/test/unit/helpers/taverna_player/application_helper_test.rb +1 -1
  48. data/test/unit/taverna_player/interaction_test.rb +2 -2
  49. data/test/unit/taverna_player/model_proxy_test.rb +58 -0
  50. data/test/unit/taverna_player/run_test.rb +103 -23
  51. data/test/unit/taverna_player/worker_test.rb +2 -0
  52. metadata +39 -12
  53. data/test/dummy/app/models/workflow.rb +0 -32
@@ -1,5 +1,5 @@
1
1
  #------------------------------------------------------------------------------
2
- # Copyright (c) 2013 The University of Manchester, UK.
2
+ # Copyright (c) 2013, 2014 The University of Manchester, UK.
3
3
  #
4
4
  # BSD Licenced. See LICENCE.rdoc for details.
5
5
  #
@@ -19,8 +19,8 @@ module TavernaPlayer
19
19
  "customization."
20
20
 
21
21
  def copy_models
22
- ["run.rb", "run_port.rb"].each do |file|
23
- copy_file file, "app/models/taverna_player/#{file}"
22
+ %w(run run_port workflow).each do |file|
23
+ copy_file "#{file}.rb", "app/models/taverna_player/#{file}.rb"
24
24
  end
25
25
  end
26
26
  end
@@ -1,5 +1,5 @@
1
1
  #------------------------------------------------------------------------------
2
- # Copyright (c) 2013 The University of Manchester, UK.
2
+ # Copyright (c) 2013, 2014 The University of Manchester, UK.
3
3
  #
4
4
  # BSD Licenced. See LICENCE.rdoc for details.
5
5
  #
@@ -11,21 +11,21 @@
11
11
  #------------------------------------------------------------------------------
12
12
 
13
13
  def player_pre_run_callback(run)
14
- w = Workflow.find(run.workflow_id)
14
+ w = TavernaPlayer::Workflow.find(run.workflow_id)
15
15
  puts "Pre-run callback called for run '#{run.name}' of workflow '#{w.id}'"
16
16
  end
17
17
 
18
18
  def player_post_run_callback(run)
19
- w = Workflow.find(run.workflow_id)
19
+ w = TavernaPlayer::Workflow.find(run.workflow_id)
20
20
  puts "Post-run callback called for run '#{run.name}' of workflow '#{w.id}'"
21
21
  end
22
22
 
23
23
  def player_run_cancelled_callback(run)
24
- w = Workflow.find(run.workflow_id)
24
+ w = TavernaPlayer::Workflow.find(run.workflow_id)
25
25
  puts "Run-cancelled callback called for run '#{run.name}' of workflow '#{w.id}'"
26
26
  end
27
27
 
28
28
  def player_run_failed_callback(run)
29
- w = Workflow.find(run.workflow_id)
29
+ w = TavernaPlayer::Workflow.find(run.workflow_id)
30
30
  puts "Run-failed callback called for run '#{run.name}' of workflow '#{w.id}'"
31
31
  end
@@ -1,5 +1,5 @@
1
1
  #------------------------------------------------------------------------------
2
- # Copyright (c) 2013 The University of Manchester, UK.
2
+ # Copyright (c) 2014 The University of Manchester, UK.
3
3
  #
4
4
  # BSD Licenced. See LICENCE.rdoc for details.
5
5
  #
@@ -10,8 +10,11 @@
10
10
  # Author: Robert Haines
11
11
  #------------------------------------------------------------------------------
12
12
 
13
- class WorkflowsController < ApplicationController
14
- def index
15
- @workflows = Workflow.all
13
+ module TavernaPlayer
14
+ class WorkflowsController < TavernaPlayer::ApplicationController
15
+ # Do not remove the next line.
16
+ include TavernaPlayer::Concerns::Controllers::WorkflowsController
17
+
18
+ # Extend the WorkflowsController here.
16
19
  end
17
20
  end
@@ -1,5 +1,5 @@
1
1
  #------------------------------------------------------------------------------
2
- # Copyright (c) 2013 The University of Manchester, UK.
2
+ # Copyright (c) 2014 The University of Manchester, UK.
3
3
  #
4
4
  # BSD Licenced. See LICENCE.rdoc for details.
5
5
  #
@@ -10,12 +10,11 @@
10
10
  # Author: Robert Haines
11
11
  #------------------------------------------------------------------------------
12
12
 
13
- require 'test_helper'
13
+ module TavernaPlayer
14
+ class Workflow < ActiveRecord::Base
15
+ # Do not remove the next line.
16
+ include TavernaPlayer::Concerns::Models::Workflow
14
17
 
15
- class WorkflowsControllerTest < ActionController::TestCase
16
- test "should get index" do
17
- get :index
18
- assert_response :success
18
+ # Extend the Workflow model here.
19
19
  end
20
-
21
20
  end
@@ -2,10 +2,11 @@
2
2
 
3
3
  TavernaPlayer.setup do |config|
4
4
 
5
- # This should be set to the name of the workflow model class in the main
6
- # application and the listed methods should also be mapped if necessary.
7
- config.workflow_model_proxy("Workflow")
8
- #config.workflow_model_proxy("Workflow") do |proxy|
5
+ # This can be set to the name of a workflow model class in the main
6
+ # application and the listed methods should also be mapped if necessary. The
7
+ # default behaviour is to use the Workflow model provided by Taverna Player.
8
+ config.workflow_model_proxy = "TavernaPlayer::Workflow"
9
+ #config.workflow_model_proxy("TavernaPlayer::Workflow") do |proxy|
9
10
  # This is the method that returns the name of the workflow file. Your
10
11
  # model MUST provide this otherwise a workflow cannot be run.
11
12
  #proxy.file_method_name = :file
@@ -33,10 +33,14 @@ module TavernaPlayer
33
33
  mattr_accessor :server_address, :server_password, :server_username
34
34
 
35
35
  # This should be set to the name of the workflow model class in the main
36
- # application via the workflow_model_proxy method below.
36
+ # application via the workflow_model_proxy method below. Defaults to the
37
+ # internal Taverna Player Workflow model (TavernaPlayer::Workflow).
37
38
  mattr_reader :workflow_proxy
39
+ @@workflow_proxy =
40
+ ModelProxy.new("TavernaPlayer::Workflow", [:file, :title, :inputs])
38
41
 
39
42
  # :call-seq:
43
+ # workflow_model_proxy = workflow_class
40
44
  # workflow_model_proxy(workflow_class) {|proxy| ...}
41
45
  #
42
46
  # Set up a proxy to the main application's workflow model. The class name
@@ -48,6 +52,12 @@ module TavernaPlayer
48
52
  yield @@workflow_proxy if block_given?
49
53
  end
50
54
 
55
+ # :stopdoc:
56
+ def self.workflow_model_proxy=(workflow_class)
57
+ TavernaPlayer.workflow_model_proxy(workflow_class)
58
+ end
59
+ # :startdoc:
60
+
51
61
  # This should be set to the name of the user model class in the main
52
62
  # application via the user_model_proxy method below. Defaults to nil.
53
63
  mattr_reader :user_proxy
@@ -45,7 +45,7 @@ module TavernaPlayer
45
45
  end
46
46
 
47
47
  def find_workflow
48
- @workflow = TavernaPlayer.workflow_proxy.class_name.find(params[:workflow_id])
48
+ @workflow = TavernaPlayer.workflow_proxy.class_const.find(params[:workflow_id])
49
49
  end
50
50
 
51
51
  def find_port
@@ -0,0 +1,41 @@
1
+ #------------------------------------------------------------------------------
2
+ # Copyright (c) 2014 The University of Manchester, UK.
3
+ #
4
+ # BSD Licenced. See LICENCE.rdoc for details.
5
+ #
6
+ # Taverna Player was developed in the BioVeL project, funded by the European
7
+ # Commission 7th Framework Programme (FP7), through grant agreement
8
+ # number 283359.
9
+ #
10
+ # Author: Robert Haines
11
+ #------------------------------------------------------------------------------
12
+
13
+ module TavernaPlayer
14
+ module Concerns
15
+ module Controllers
16
+ module WorkflowsController
17
+
18
+ extend ActiveSupport::Concern
19
+
20
+ included do
21
+ respond_to :html, :json
22
+
23
+ before_filter :find_workflows, :only => :index
24
+
25
+ private
26
+
27
+ def find_workflows
28
+ @workflows = Workflow.all
29
+ end
30
+
31
+ end # included
32
+
33
+ # GET /workflows
34
+ def index
35
+
36
+ end
37
+
38
+ end
39
+ end
40
+ end
41
+ end
@@ -24,10 +24,10 @@ module TavernaPlayer
24
24
 
25
25
  # Each run is spawned from a workflow. This provides the link to the
26
26
  # workflow model in the parent app, whatever it calls its model.
27
- belongs_to :workflow, :class_name => TavernaPlayer.workflow_proxy.class_name.to_s
27
+ belongs_to :workflow, :class_name => TavernaPlayer.workflow_proxy.class_name
28
28
 
29
29
  unless TavernaPlayer.user_proxy.nil?
30
- belongs_to :user, :class_name => TavernaPlayer.user_proxy.class_name.to_s
30
+ belongs_to :user, :class_name => TavernaPlayer.user_proxy.class_name
31
31
  end
32
32
 
33
33
  has_many :inputs, :class_name => "TavernaPlayer::RunPort::Input",
@@ -85,6 +85,7 @@ module TavernaPlayer
85
85
  after_create :populate_child_inputs, :if => :has_parent?
86
86
  after_create :enqueue
87
87
  before_destroy :complete?
88
+ after_destroy :destroy_failed_delayed_jobs
88
89
 
89
90
  private
90
91
 
@@ -110,7 +111,14 @@ module TavernaPlayer
110
111
  def enqueue
111
112
  worker = TavernaPlayer::Worker.new(self)
112
113
  job = Delayed::Job.enqueue worker, :queue => TavernaPlayer.job_queue_name
113
- update_attributes(:delayed_job => job, :status_message_key => "pending")
114
+
115
+ self.delayed_job = job
116
+ self.status_message_key = "pending"
117
+ save
118
+ end
119
+
120
+ def destroy_failed_delayed_jobs
121
+ delayed_job.destroy unless delayed_job.nil?
114
122
  end
115
123
 
116
124
  end # included
@@ -137,22 +145,25 @@ module TavernaPlayer
137
145
  #
138
146
  # See the note above about the :cancelled state.
139
147
  def cancel
140
- return if complete?
148
+ return unless incomplete?
141
149
 
142
- # If the run has a delayed job (still) and it hasn't been locked yet
143
- # then we just remove it from the queue directly and mark the run as
144
- # cancelled.
150
+ # Set the stop flag for all cases.
151
+ self.stop = true
152
+
153
+ # If the run has a delayed job and it hasn't been locked yet, or it
154
+ # has failed, then we just remove it from the queue directly and
155
+ # mark the run as cancelled.
145
156
  unless delayed_job.nil?
146
157
  delayed_job.with_lock do
147
- if delayed_job.locked_by.nil?
158
+ if delayed_job.locked_by.nil? || !delayed_job.failed_at.nil?
148
159
  delayed_job.destroy
149
- update_attribute(:saved_state, "cancelled")
150
- update_attribute(:status_message_key, "cancelled")
160
+ self.state = :cancelled
161
+ self.status_message_key = "cancelled"
151
162
  end
152
163
  end
153
164
  end
154
165
 
155
- update_attribute(:stop, true)
166
+ save
156
167
  end
157
168
 
158
169
  # Return state as a symbol. If a run is running, but has been asked to
@@ -181,6 +192,14 @@ module TavernaPlayer
181
192
  I18n.t("taverna_player.status.#{key}")
182
193
  end
183
194
 
195
+ def pending?
196
+ state == :pending
197
+ end
198
+
199
+ def initialized?
200
+ state == :initialized
201
+ end
202
+
184
203
  def running?
185
204
  state == :running
186
205
  end
@@ -205,10 +224,19 @@ module TavernaPlayer
205
224
  state == :failed
206
225
  end
207
226
 
208
- # This is used as a catch-all for finished, cancelled, failed and
209
- # timeout
227
+ def job_failed?
228
+ !delayed_job.nil? && !delayed_job.failed_at.nil?
229
+ end
230
+
231
+ # This is used as a catch-all for pending?, initialized? and running?
232
+ def incomplete?
233
+ running? || pending? || initialized?
234
+ end
235
+
236
+ # This is used as a catch-all for finished, cancelled, failed,
237
+ # job_failed? and timeout
210
238
  def complete?
211
- finished? || cancelled? || failed? || timeout?
239
+ finished? || cancelled? || failed? || job_failed? || timeout?
212
240
  end
213
241
 
214
242
  def has_parent?
@@ -103,7 +103,8 @@ module TavernaPlayer
103
103
  md = metadata
104
104
  md = Hash.new if md.nil?
105
105
  md[field] = value
106
- update_attribute(:metadata, md)
106
+ self.metadata = md
107
+ save
107
108
  end
108
109
 
109
110
  end # included
@@ -0,0 +1,44 @@
1
+ #------------------------------------------------------------------------------
2
+ # Copyright (c) 2014 The University of Manchester, UK.
3
+ #
4
+ # BSD Licenced. See LICENCE.rdoc for details.
5
+ #
6
+ # Taverna Player was developed in the BioVeL project, funded by the European
7
+ # Commission 7th Framework Programme (FP7), through grant agreement
8
+ # number 283359.
9
+ #
10
+ # Author: Robert Haines
11
+ #------------------------------------------------------------------------------
12
+
13
+ module TavernaPlayer
14
+ module Concerns
15
+ module Models
16
+ module Workflow
17
+
18
+ extend ActiveSupport::Concern
19
+
20
+ included do
21
+ attr_accessible :author, :description, :file, :title
22
+
23
+ has_many :runs, :class_name => "TavernaPlayer::Run"
24
+ end # included
25
+
26
+ def inputs
27
+ workflow = File.open(file)
28
+ model = T2Flow::Parser.new.parse(workflow)
29
+
30
+ result = []
31
+ model.sources.each do |i|
32
+ description = i.descriptions.nil? ? "" : i.descriptions.join
33
+ example = i.example_values.nil? ? "" : i.example_values.join
34
+ result << { :name => i.name, :description => description,
35
+ :example => example }
36
+ end
37
+
38
+ result
39
+ end
40
+
41
+ end
42
+ end
43
+ end
44
+ end
@@ -1,5 +1,5 @@
1
1
  #------------------------------------------------------------------------------
2
- # Copyright (c) 2013 The University of Manchester, UK.
2
+ # Copyright (c) 2013, 2014 The University of Manchester, UK.
3
3
  #
4
4
  # BSD Licenced. See LICENCE.rdoc for details.
5
5
  #
@@ -15,21 +15,27 @@ module TavernaPlayer
15
15
  attr_reader :class_name
16
16
 
17
17
  def initialize(class_name, method_names = [])
18
- if class_name.is_a?(String)
19
- begin
20
- @class_name = Object.const_get(class_name)
21
- rescue NameError
22
- @class_name = class_name.constantize
23
- end
24
- end
18
+ @class_name = root_name(class_name.to_s)
25
19
 
26
20
  method_names.each do |name|
27
21
  add_method(name.to_sym)
28
22
  end
29
23
  end
30
24
 
25
+ def class_const
26
+ @const ||= begin
27
+ Object.const_get(@class_name)
28
+ rescue NameError
29
+ @class_name.constantize
30
+ end
31
+ end
32
+
31
33
  private
32
34
 
35
+ def root_name(name)
36
+ name.start_with?("::") ? name : "::#{name}"
37
+ end
38
+
33
39
  def add_method(name)
34
40
  setter = "#{name}_method_name=".to_sym
35
41
  mapper = name
@@ -11,5 +11,5 @@
11
11
  #------------------------------------------------------------------------------
12
12
 
13
13
  module TavernaPlayer
14
- VERSION = "0.8.0"
14
+ VERSION = "0.9.0"
15
15
  end
@@ -36,6 +36,7 @@ Gem::Specification.new do |s|
36
36
  s.add_dependency "rails", "~> 3.2.12"
37
37
  s.add_dependency "jquery-rails", "~> 3.0"
38
38
  s.add_dependency "paperclip", "~> 4.1"
39
+ s.add_dependency "taverna-t2flow", "~> 0.5.1"
39
40
  s.add_dependency "t2-server", "~> 1.1"
40
41
  s.add_dependency "delayed_job_active_record", "~> 4.0"
41
42
  s.add_dependency "daemons", "~> 1.1.9"
@@ -26,7 +26,7 @@
26
26
  <br />
27
27
 
28
28
  <%= link_to "Home", main_app.root_path %> |
29
- <%= link_to "Workflows", main_app.workflows_path %> |
29
+ <%= link_to "Workflows", taverna_player.workflows_path %> |
30
30
  <%= link_to "Runs", taverna_player.runs_path %> |
31
31
  <%= link_to "Service Credentials", taverna_player.service_credentials_path %> |
32
32
  <%= link_to "Job Queue", taverna_player.job_queue_path %>
@@ -13,11 +13,8 @@
13
13
  # Taverna Player configuration
14
14
 
15
15
  TavernaPlayer.setup do |config|
16
- config.workflow_model_proxy("Workflow") do |proxy|
17
- proxy.file_method_name = :file
18
- end
19
16
  config.user_model_proxy = "User"
20
- config.current_user_callback = Proc.new { User.find(1) }
17
+ config.current_user_callback = Proc.new { User.first }
21
18
 
22
19
  # Move admin resources into their own namespace.
23
20
  config.admin_scope = "admin"
@@ -1,5 +1,5 @@
1
1
  #------------------------------------------------------------------------------
2
- # Copyright (c) 2013 The University of Manchester, UK.
2
+ # Copyright (c) 2013, 2014 The University of Manchester, UK.
3
3
  #
4
4
  # BSD Licenced. See LICENCE.rdoc for details.
5
5
  #
@@ -11,12 +11,6 @@
11
11
  #------------------------------------------------------------------------------
12
12
 
13
13
  Rails.application.routes.draw do
14
-
15
14
  root :to => "home#index"
16
-
17
- resources :workflows, :only => :index do
18
- resources :runs, :controller => "TavernaPlayer::Runs", :except => :edit
19
- end
20
-
21
15
  mount TavernaPlayer::Engine, :at => "/"
22
16
  end