Class: Kuroko2::Token

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

Constant Summary collapse

WORKING =
0
FINISHED =
1
FAILURE =
2
WAITING =
3
CRITICAL =
9
STATUSES =
{
  WORKING  => :working,
  FINISHED => :finished,
  FAILURE  => :failure,
  CRITICAL => :critical,
  WAITING  => :waiting,
}.freeze

Instance Method Summary collapse

Instance Method Details

#cancelable?Boolean

Returns:

  • (Boolean)


80
81
82
83
84
85
86
87
88
89
90
91
# File 'app/models/kuroko2/token.rb', line 80

def cancelable?
  case status
  when WORKING, WAITING
    children.many? && children.all? do |child|
      child.status == FINISHED || child.cancelable?
    end
  when FAILURE
    true
  else
    false
  end
end

#critical?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'app/models/kuroko2/token.rb', line 47

def critical?
  status == CRITICAL
end

#failure?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'app/models/kuroko2/token.rb', line 39

def failure?
  status == FAILURE
end

#finished?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'app/models/kuroko2/token.rb', line 43

def finished?
  status == FINISHED
end

#mark_as_critical(error) ⇒ Object



59
60
61
62
# File 'app/models/kuroko2/token.rb', line 59

def mark_as_critical(error)
  self.status  = CRITICAL
  self.message = error.message
end

#mark_as_failureObject



55
56
57
# File 'app/models/kuroko2/token.rb', line 55

def mark_as_failure
  self.status = FAILURE
end

#mark_as_finishedObject



64
65
66
# File 'app/models/kuroko2/token.rb', line 64

def mark_as_finished
  self.status = FINISHED
end

#mark_as_waitingObject



72
73
74
# File 'app/models/kuroko2/token.rb', line 72

def mark_as_waiting
  self.status = WAITING
end

#mark_as_workingObject



68
69
70
# File 'app/models/kuroko2/token.rb', line 68

def mark_as_working
  self.status = WORKING
end

#status_nameObject



76
77
78
# File 'app/models/kuroko2/token.rb', line 76

def status_name
  STATUSES[status].to_s
end

#waiting?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'app/models/kuroko2/token.rb', line 51

def waiting?
  status == WAITING
end

#working?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'app/models/kuroko2/token.rb', line 35

def working?
  status == WORKING
end