Class: Katello::Glue::Queue

Inherits:
Object
  • Object
show all
Defined in:
app/lib/katello/glue/queue.rb

Constant Summary collapse

STATUS =
%w(pending running failed completed rollbacked)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(previous_queue = nil) ⇒ Queue

we can put more queues sequentially. E.g. on queue before saving a record, another after saving. If something in later queue fails we roll-back also everything in previous queues.



20
21
22
23
# File 'app/lib/katello/glue/queue.rb', line 20

def initialize(previous_queue = nil)
  @previous_queue = previous_queue
  @items          = []
end

Instance Attribute Details

#itemsObject (readonly)

Returns the value of attribute items.



14
15
16
# File 'app/lib/katello/glue/queue.rb', line 14

def items
  @items
end

Instance Method Details

#allObject



38
39
40
41
42
43
# File 'app/lib/katello/glue/queue.rb', line 38

def all
  ret = []
  ret.concat(@previous_queue.all) if @previous_queue
  ret.concat(items.sort)
  ret
end

#clearObject



48
49
50
# File 'app/lib/katello/glue/queue.rb', line 48

def clear
  @items = [] && true
end

#create(options) ⇒ Object



25
26
27
28
# File 'app/lib/katello/glue/queue.rb', line 25

def create(options)
  options[:status] ||= default_status
  Glue::Task.new(options).tap { |t| items << t }
end

#delete(item) ⇒ Object



30
31
32
# File 'app/lib/katello/glue/queue.rb', line 30

def delete(item)
  @items.delete item
end

#find_by_name(name) ⇒ Object



34
35
36
# File 'app/lib/katello/glue/queue.rb', line 34

def find_by_name(name)
  items.each { |task| return task if task.name == name }
end

#to_logObject



52
53
54
# File 'app/lib/katello/glue/queue.rb', line 52

def to_log
  all.collect(&:to_log).join ", "
end