Class: MotherBrain::JobRecord

Inherits:
Object
  • Object
show all
Includes:
MB::Job::States
Defined in:
lib/mb/job_record.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(job) ⇒ JobRecord

Returns a new instance of JobRecord.

Parameters:



17
18
19
20
# File 'lib/mb/job_record.rb', line 17

def initialize(job)
  @id = job.id
  mass_assign(job)
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/mb/job_record.rb', line 5

def id
  @id
end

#resultObject (readonly)

Returns the value of attribute result.



7
8
9
# File 'lib/mb/job_record.rb', line 7

def result
  @result
end

#stateObject (readonly)

Returns the value of attribute state.



8
9
10
# File 'lib/mb/job_record.rb', line 8

def state
  @state
end

#statusObject (readonly)

Returns the value of attribute status.



9
10
11
# File 'lib/mb/job_record.rb', line 9

def status
  @status
end

#status_bufferObject (readonly)

Returns the value of attribute status_buffer.



10
11
12
# File 'lib/mb/job_record.rb', line 10

def status_buffer
  @status_buffer
end

#time_endObject (readonly)

Returns the value of attribute time_end.



14
15
16
# File 'lib/mb/job_record.rb', line 14

def time_end
  @time_end
end

#time_startObject (readonly)

Returns the value of attribute time_start.



13
14
15
# File 'lib/mb/job_record.rb', line 13

def time_start
  @time_start
end

#typeObject (readonly)

Returns the value of attribute type.



11
12
13
# File 'lib/mb/job_record.rb', line 11

def type
  @type
end

Instance Method Details

#to_hashHash

Returns:

  • (Hash)


34
35
36
37
38
39
40
41
42
43
44
# File 'lib/mb/job_record.rb', line 34

def to_hash
  {
    id: id,
    type: type,
    state: state,
    status: status,
    result: result,
    time_start: time_start,
    time_end: time_end
  }
end

#to_json(options = {}) ⇒ String

Parameters:

  • options (Hash) (defaults to: {})

    a set of options to pass to MultiJson.encode

Returns:

  • (String)


50
51
52
# File 'lib/mb/job_record.rb', line 50

def to_json(options = {})
  MultiJson.encode(self.to_hash, options)
end

#update(job) ⇒ self

Update the instantiated JobRecord with the attributes of the given Job

Parameters:

  • job (Job)

    the updated job to update the record with

Returns:

  • (self)


28
29
30
31
# File 'lib/mb/job_record.rb', line 28

def update(job)
  mass_assign(job)
  self
end