Class: NERA::JobRecords

Inherits:
Object
  • Object
show all
Defined in:
lib/nera/nera_job_records.rb

Overview

This class access the simulator table.

Constant Summary collapse

ATTRIBUTES =

keys of the simulator table

[ [:id, Integer],
  [:state, Symbol],
  [:simulator, String],
  [:parameter_id, Integer],
  [:run_id, Integer],
  [:number_of_runs, Integer],
  [:created_at, DateTime],
  [:updated_at, DateTime],
  [:host_name, String]
]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(db_file) ⇒ JobRecords

db_file is the path to database file



24
25
26
# File 'lib/nera/nera_job_records.rb', line 24

def initialize( db_file)
  @db = NERA::Database.new( db_file)
end

Class Method Details

.create_table(db_file) ⇒ Object

if file already exists, returns false



34
35
36
# File 'lib/nera/nera_job_records.rb', line 34

def self.create_table( db_file)
  NERA::Database.create_table( db_file)
end

Instance Method Details

#add(sim_class, param_id, r_id, num_runs) ⇒ Object

sim_class must be a subclass of NERA::Simulator



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/nera/nera_job_records.rb', line 47

def add( sim_class, param_id, r_id, num_runs)
  unless sim_class.is_a?(Class) and sim_class.superclass == NERA::Simulator and param_id.is_a?(Integer) and r_id.is_a?(Integer) and num_runs.is_a?(Integer)
    raise ArgumentError, "Each argument must be an Integer"
  end
  if param_id <= 0 or r_id <= 0 or num_runs <= 0
    raise ArgumentError, "Each argument must be a positive integer."
  end
  d = DateTime.now
  h = { :state => :created, :simulator => sim_class.to_s, :parameter_id => param_id, :run_id => r_id,
    :number_of_runs => num_runs, :created_at => d, :updated_at => d, :host_name => nil}
  id = @db.add( h)
  return id
end

#destroy(id) ⇒ Object

Raises:

  • (ArgumentError)


105
106
107
108
# File 'lib/nera/nera_job_records.rb', line 105

def destroy( id)
  raise ArgumentError unless id.is_a?(Integer)
  @db.destroy(id)
end

#find_by_id(i) ⇒ Object



73
74
75
# File 'lib/nera/nera_job_records.rb', line 73

def find_by_id( i)
  @db.find_by_id( i)
end

#keysObject

return keys of the simulator table



39
40
41
42
43
44
# File 'lib/nera/nera_job_records.rb', line 39

def keys
  keys = ATTRIBUTES.map do |x|
    x[0]
  end
  return keys
end

#list_allObject



61
62
63
64
# File 'lib/nera/nera_job_records.rb', line 61

def list_all
  l = @db.find_all do |r| true end
  return l.to_a
end

#list_createdObject



66
67
68
69
70
71
# File 'lib/nera/nera_job_records.rb', line 66

def list_created
  l = @db.find_all do |r|
    r[:state] == :created
  end
  return l.to_a
end

#set_yaml_file(yaml_path) ⇒ Object

argument is the path to jobs.yml



29
30
31
# File 'lib/nera/nera_job_records.rb', line 29

def set_yaml_file( yaml_path)
  @db.set_yaml_file( yaml_path)
end

#transactionObject



110
111
112
113
114
# File 'lib/nera/nera_job_records.rb', line 110

def transaction
  @db.transaction{
    yield
  }
end

#update_to_state_copied(id, hostname) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/nera/nera_job_records.rb', line 77

def update_to_state_copied( id, hostname)
  unless id.is_a?(Integer) and hostname.is_a?(String)
    raise ArgumentError, "Type of the argument is invalid."
  end
  
  found = @db.find_by_id( id)
  return nil  if found == nil

  found[:state] = :copied
  found[:updated_at] = DateTime.now
  found[:host_name] = hostname
  @db.update(found)
end

#update_to_state_submitted(id, hostname) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/nera/nera_job_records.rb', line 91

def ( id, hostname)
  unless id.is_a?(Integer) and hostname.is_a?(String)
    raise ArgumentError, "Type of the argument is invalid."
  end
  
  found = @db.find_by_id( id)
  return nil  if found == nil

  found[:state] = :submitted
  found[:updated_at] = DateTime.now
  found[:host_name] = hostname
  @db.update(found)
end