Class: Pvectl::Presenters::TaskEntry

Inherits:
Base
  • Object
show all
Defined in:
lib/pvectl/presenters/task_entry.rb,
sig/pvectl/presenters/task_entry.rbs

Overview

Presenter for task list entries (pvectl logs vm/ct).

Instance Method Summary collapse

Methods inherited from Base

#format_bytes, #format_firewall, #format_firewall_rules, #format_task_history, #resource, #tags_array, #tags_display, #template_display, #to_description, #to_wide_row, #uptime_human, #wide_columns

Instance Method Details

#columnsArray[String]

Returns:



7
8
9
# File 'lib/pvectl/presenters/task_entry.rb', line 7

def columns
  %w[STARTTIME TYPE STATUS USER DURATION NODE]
end

#extra_columnsArray[String]

Returns:



11
12
13
# File 'lib/pvectl/presenters/task_entry.rb', line 11

def extra_columns
  %w[UPID ENDTIME ID PID]
end

#extra_values(model, **_context) ⇒ Array[String]

Parameters:

Returns:



26
27
28
29
30
31
32
33
# File 'lib/pvectl/presenters/task_entry.rb', line 26

def extra_values(model, **_context)
  [
    model.upid || "-",
    format_time(model.endtime),
    model.id || "-",
    model.pid&.to_s || "-"
  ]
end

#format_duration(seconds) ⇒ String

Parameters:

Returns:



57
58
59
60
61
62
63
64
65
66
# File 'lib/pvectl/presenters/task_entry.rb', line 57

def format_duration(seconds)
  return "-" if seconds.nil?
  if seconds < 60
    "#{seconds}s"
  elsif seconds < 3600
    "#{seconds / 60}m#{seconds % 60}s"
  else
    "#{seconds / 3600}h#{(seconds % 3600) / 60}m"
  end
end

#format_time(timestamp) ⇒ String

Parameters:

Returns:



52
53
54
55
# File 'lib/pvectl/presenters/task_entry.rb', line 52

def format_time(timestamp)
  return "-" if timestamp.nil?
  Time.at(timestamp).strftime("%Y-%m-%d %H:%M:%S")
end

#to_hash(model) ⇒ Hash[String, untyped]

Parameters:

Returns:



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/pvectl/presenters/task_entry.rb', line 35

def to_hash(model)
  {
    "starttime" => model.starttime,
    "endtime" => model.endtime,
    "type" => model.type,
    "status" => model.status,
    "exitstatus" => model.exitstatus,
    "user" => model.user,
    "duration" => model.duration,
    "node" => model.node,
    "id" => model.id,
    "upid" => model.upid
  }
end

#to_row(model, **_context) ⇒ Array[String]

Parameters:

Returns:



15
16
17
18
19
20
21
22
23
24
# File 'lib/pvectl/presenters/task_entry.rb', line 15

def to_row(model, **_context)
  [
    format_time(model.starttime),
    model.type || "-",
    model.exitstatus || model.status || "-",
    model.user || "-",
    format_duration(model.duration),
    model.node || "-"
  ]
end