Sha256: f1908599ae5b3c78ba654be30fc17851e5a5cc8bf3b92ea2586616254b4e9d71

Contents?: true

Size: 701 Bytes

Versions: 5

Compression:

Stored size: 701 Bytes

Contents

class Task
  attr_reader :name, :status, :priority, :action, :timestamp

  def initialize opts
    @name      = opts[:name]
    @status    = opts[:status]
    @priority  = opts[:priority] || 0
    @action    = opts[:action]
    update_ts
  end

  def status=s
    if Orchestration::Queue::STATUS.include?(s)
      update_ts
      @status = s
    else
      raise "invalid STATE #{s}"
    end
  end

  def to_s
    "#{name}\t #{priority}\t #{status}\t #{action}"
  end

  def as_json options = {}
    super :only => [:name, :timestamp, :status]
  end

  private
  def update_ts
    @timestamp = Time.now
  end

  # sort based on priority
  def <=> other
    self.priority <=> other.priority
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
foreman_discovery-1.0.0 test/foreman_app/lib/task.rb
foreman_discovery-1.0.0.rc4 test/foreman_app/lib/task.rb
foreman_discovery-1.0.0.rc3 test/foreman_app/lib/task.rb
foreman_discovery-1.0.0.rc2 test/foreman_app/lib/task.rb
foreman_discovery-1.0.0.rc1 test/foreman_app/lib/task.rb