Class: TavernaPlayer::Worker

Inherits:
Object
  • Object
show all
Includes:
Concerns::Callback, Concerns::Zip
Defined in:
lib/taverna_player/worker.rb

Constant Summary collapse

INTERACTION_REGEX =

How to get the interaction presentation frame out of the interaction page.

/document\.getElementById\(\'presentationFrame\'\)\.src = \"(.+)\";/

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Concerns::Zip

#read_file_from_zip

Methods included from Concerns::Callback

#callback

Constructor Details

#initialize(run, workflow_file = nil) ⇒ Worker

The workflow file to be run can be specified explicitly or it will be taken from the workflow model.



25
26
27
28
29
# File 'lib/taverna_player/worker.rb', line 25

def initialize(run, workflow_file = nil)
  @run = run
  @workflow = workflow_file || TavernaPlayer.workflow_proxy.file(@run.workflow)
  @server = "Run not yet initialized"
end

Instance Attribute Details

#runObject (readonly)

Returns the value of attribute run.



18
19
20
# File 'lib/taverna_player/worker.rb', line 18

def run
  @run
end

Instance Method Details

#max_attemptsObject

This tells delayed_job to only try and complete each run once.



38
39
40
# File 'lib/taverna_player/worker.rb', line 38

def max_attempts
  1
end

#performObject



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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
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
135
# File 'lib/taverna_player/worker.rb', line 42

def perform
  return unless run_callback(TavernaPlayer.pre_run_callback, "pre-callback")

  status_message("connect")

  @server = URI.parse(ENV["TAVERNA_URI"] || TavernaPlayer.server_address)
  credentials = server_credentials
  conn_params = TavernaPlayer.server_connection

  begin
    server = T2Server::Server.new(@server, conn_params)
    workflow = File.read(@workflow)
    run = create_run(server, workflow, credentials)

    # If run is nil here then we could have failed or have been cancelled.
    return if run.nil?

    status_message("initialized")

    @run.run_id = run.id
    @run.state = run.status
    @run.create_time = run.create_time
    @run.save

    unless @run.inputs.size == 0
      status_message("inputs")
      @run.inputs.each do |input|
        unless input.file.blank?
          run.input_port(input.name).file = input.file.path
        else
          run.input_port(input.name).value = input.value
        end
      end
    end

    # Just add in all service credentials right now
    TavernaPlayer::ServiceCredential.all.each do |cred|
      run.add_password_credential(cred.uri, cred., cred.password)
    end

    status_message("start")
    run.name = @run.name

    # Try and start the run bearing in mind that the server might be at
    # the limit of runs that it can run at once.
    while !run.start
      status_message("busy")

      if cancelled?
        cancel(run)
        return
      end

      sleep(TavernaPlayer.server_retry_interval)
    end

    @run.state = run.status
    @run.start_time = run.start_time
    @run.save

    status_message("running")
    until run.finished?
      sleep(TavernaPlayer.server_poll_interval)
      waiting = false

      if cancelled?
        cancel(run)
        return
      end

      waiting = interactions(run, credentials)

      status_message(waiting ? "interact" : "running")
    end

    status_message("outputs")
    download_outputs(run)
    download_log(run)

    @run.outputs = process_outputs(run)
    @run.finish_time = run.finish_time
    @run.save

    run.delete
  rescue => exception
    failed(exception, run)
    return
  end

  return unless run_callback(TavernaPlayer.post_run_callback, "post-callback")

  @run.state = :finished
  status_message("finished")
end

#serverObject

Return the server address that this worker is using. Used mainly for testing.



33
34
35
# File 'lib/taverna_player/worker.rb', line 33

def server
  @server.to_s
end