Method: TaskInfo#initialize

Defined in:
lib/task_info.rb

#initialize(job_data) ⇒ TaskInfo

Creates a new TaskInfo object, storing the parameters the user gave us to invoke the job for later use. The user can give us a Hash containing the parameters that the job was started with, or a String that is the JSON-dumped version of that data (also obtainable from TaskInfo objects via to_json).



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/task_info.rb', line 36

def initialize(job_data)
  if job_data.class == String
    begin
      job_data = JSON.load(job_data)
    rescue JSON::ParserError
      raise BadConfigurationException.new("job data not JSONable")
    end
  end

  if job_data.class != Hash
    raise BadConfigurationException.new("job data not a Hash")
  end
  @job_data = job_data

  # To prevent us from repeatedly grabbing (potentially) large files over the
  # network repeatedly, we keep a local, cached copy of the task's standard
  # output, error, and metadata - initially empty, but pulled in the first
  # time that the user asks for it. Since we expose this functionality through
  # the accessor methods below, we should not use attr_accessor or attr_reader
  # to directly expose this variables.
  @output = nil
  @error = nil
  @metadata = nil

  # To prevent concurrent threads from pulling in output multiple times, we
  # guard access to remotely grabbing output/error/metadata with this
  # lock.
  @lock = Mutex.new
end