Class: Kuroko2::JobInstance

Inherits:
ApplicationRecord show all
Includes:
TableNameCustomizable
Defined in:
app/models/kuroko2/job_instance.rb

Instance Method Summary collapse

Instance Method Details

#cancelObject



46
47
48
49
50
# File 'app/models/kuroko2/job_instance.rb', line 46

def cancel
  self.tokens.destroy(*self.tokens)
  self.executions.destroy(*self.executions)
  self.touch(:canceled_at)
end

#cancelable?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'app/models/kuroko2/job_instance.rb', line 42

def cancelable?
  tokens.first.try(:cancelable?)
end

#error?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'app/models/kuroko2/job_instance.rb', line 34

def error?
  working? && error_at?
end

#execution_minutesObject



65
66
67
# File 'app/models/kuroko2/job_instance.rb', line 65

def execution_minutes
  (((error_at || canceled_at || finished_at || Time.current) - created_at).to_f / 60).round(2)
end

#log_memory_consumption(value) ⇒ Object

Log given value if it is greater than stored one. This logging is not so important that we can ignore race condition, so we use ‘#update` and `#create_association` without bang here.

Parameters:

  • value (Intger)


56
57
58
59
60
61
62
63
# File 'app/models/kuroko2/job_instance.rb', line 56

def log_memory_consumption(value)
  if memory_consumption_log
    max = [value, memory_consumption_log.value].max
    memory_consumption_log.update(value: max)
  else
    create_memory_consumption_log(value: value)
  end
end

#statusObject



69
70
71
72
73
74
75
76
77
78
79
# File 'app/models/kuroko2/job_instance.rb', line 69

def status
  if finished_at?
    'success'
  elsif canceled_at?
    'canceled'
  elsif error_at?
    'error'
  else
    'working'
  end
end

#working?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'app/models/kuroko2/job_instance.rb', line 38

def working?
  !finished_at? && !canceled_at?
end