Class: Quandl::Sandbox::Job

Inherits:
Object
  • Object
show all
Defined in:
lib/quandl/sandbox/job.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Job

Returns a new instance of Job.



5
6
7
8
9
# File 'lib/quandl/sandbox/job.rb', line 5

def initialize(*args)
  options = args.extract_options!.symbolize_keys!
  self.repository = Quandl::Sandbox::Repository.new(options[:repository]) if options[:repository].present?
  self.server = Quandl::Sandbox::Server.find( options[:server_id] ) if options[:server_id].present?
end

Instance Attribute Details

#attemptsObject

Returns the value of attribute attempts.



3
4
5
# File 'lib/quandl/sandbox/job.rb', line 3

def attempts
  @attempts
end

#outputObject

Returns the value of attribute output.



3
4
5
# File 'lib/quandl/sandbox/job.rb', line 3

def output
  @output
end

#repositoryObject

Returns the value of attribute repository.



3
4
5
# File 'lib/quandl/sandbox/job.rb', line 3

def repository
  @repository
end

#serverObject

Returns the value of attribute server.



3
4
5
# File 'lib/quandl/sandbox/job.rb', line 3

def server
  @server
end

#server_idObject

Returns the value of attribute server_id.



3
4
5
# File 'lib/quandl/sandbox/job.rb', line 3

def server_id
  @server_id
end

Instance Method Details

#datasetsObject



11
12
13
# File 'lib/quandl/sandbox/job.rb', line 11

def datasets
  @datasets ||= Quandl::Sandbox::Dataset.from_output( output[:stdout] )
end

#executeObject



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/quandl/sandbox/job.rb', line 15

def execute
  # ensure the ssh daemon has started
  server.ensure_connection_established!
  # run commands that need to happen before importer
  server.exec( repository.script.before_execute )
  # execute importer
  self.output = server.exec( repository.script.execute )
rescue => err
  Quandl::Logger.error( err )
ensure
  server.delete
end