Class: Pvectl::Models::Task

Inherits:
Base
  • Object
show all
Defined in:
lib/pvectl/models/task.rb

Overview

Represents a Proxmox task (asynchronous operation).

Tasks are returned by lifecycle operations (start, stop, etc.). The UPID (Unique Process ID) identifies the task.

Examples:

Creating a Task model

task = Task.new(upid: "UPID:pve1:...", status: "running")
task.pending? #=> true
task.completed? #=> false

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Task

Creates a new Task model from attributes.

Parameters:

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

    Task attributes from API



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/pvectl/models/task.rb', line 45

def initialize(attrs = {})
  super(attrs)
  @upid = @attributes[:upid]
  @node = @attributes[:node]
  @type = @attributes[:type]
  @status = @attributes[:status]
  @exitstatus = @attributes[:exitstatus]
  @starttime = @attributes[:starttime]
  @endtime = @attributes[:endtime]
  @user = @attributes[:user]
end

Instance Attribute Details

#endtimeInteger? (readonly)

Returns Task end time (Unix timestamp).

Returns:

  • (Integer, nil)

    Task end time (Unix timestamp)



37
38
39
# File 'lib/pvectl/models/task.rb', line 37

def endtime
  @endtime
end

#exitstatusString? (readonly)

Returns Exit status (OK, ERROR, etc.).

Returns:

  • (String, nil)

    Exit status (OK, ERROR, etc.)



31
32
33
# File 'lib/pvectl/models/task.rb', line 31

def exitstatus
  @exitstatus
end

#nodeString (readonly)

Returns Node where task runs.

Returns:

  • (String)

    Node where task runs



22
23
24
# File 'lib/pvectl/models/task.rb', line 22

def node
  @node
end

#starttimeInteger? (readonly)

Returns Task start time (Unix timestamp).

Returns:

  • (Integer, nil)

    Task start time (Unix timestamp)



34
35
36
# File 'lib/pvectl/models/task.rb', line 34

def starttime
  @starttime
end

#statusString (readonly)

Returns Task status (running, stopped).

Returns:

  • (String)

    Task status (running, stopped)



28
29
30
# File 'lib/pvectl/models/task.rb', line 28

def status
  @status
end

#typeString (readonly)

Returns Task type (qmstart, qmstop, etc.).

Returns:

  • (String)

    Task type (qmstart, qmstop, etc.)



25
26
27
# File 'lib/pvectl/models/task.rb', line 25

def type
  @type
end

#upidString (readonly)

Returns Unique Process ID.

Returns:

  • (String)

    Unique Process ID



19
20
21
# File 'lib/pvectl/models/task.rb', line 19

def upid
  @upid
end

#userString? (readonly)

Returns User who started the task.

Returns:

  • (String, nil)

    User who started the task



40
41
42
# File 'lib/pvectl/models/task.rb', line 40

def user
  @user
end

Instance Method Details

#completed?Boolean

Checks if the task has completed.

Returns:

  • (Boolean)

    true if status is not “running”



67
68
69
# File 'lib/pvectl/models/task.rb', line 67

def completed?
  !pending?
end

#durationInteger?

Returns task duration in seconds.

Returns:

  • (Integer, nil)

    duration or nil if not available



88
89
90
91
92
# File 'lib/pvectl/models/task.rb', line 88

def duration
  return nil unless endtime && starttime

  endtime - starttime
end

#failed?Boolean

Checks if the task failed.

Returns:

  • (Boolean)

    true if completed with non-OK exitstatus



81
82
83
# File 'lib/pvectl/models/task.rb', line 81

def failed?
  completed? && exitstatus != "OK"
end

#pending?Boolean

Checks if the task is still running.

Returns:

  • (Boolean)

    true if status is “running”



60
61
62
# File 'lib/pvectl/models/task.rb', line 60

def pending?
  status == "running"
end

#successful?Boolean

Checks if the task completed successfully.

Returns:

  • (Boolean)

    true if completed with “OK” exitstatus



74
75
76
# File 'lib/pvectl/models/task.rb', line 74

def successful?
  completed? && exitstatus == "OK"
end