Class: Orchestration::Queue

Inherits:
Object
  • Object
show all
Defined in:
lib/orchestration/queue.rb

Overview

Represents tasks queue for orchestration

Constant Summary collapse

STATUS =
%w[ pending running failed completed rollbacked conflict canceled]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeQueue

Returns a new instance of Queue.


9
10
11
# File 'lib/orchestration/queue.rb', line 9

def initialize
  @items = []
end

Instance Attribute Details

#itemsObject (readonly)

Returns the value of attribute items


6
7
8
# File 'lib/orchestration/queue.rb', line 6

def items
  @items
end

Instance Method Details

#allObject


26
27
28
# File 'lib/orchestration/queue.rb', line 26

def all
  items.sort
end

#clearObject


38
39
40
# File 'lib/orchestration/queue.rb', line 38

def clear
  @items = [] && true
end

#countObject


30
31
32
# File 'lib/orchestration/queue.rb', line 30

def count
  items.count
end

#create(options) ⇒ Object


13
14
15
16
# File 'lib/orchestration/queue.rb', line 13

def create options
  options[:status] ||= default_status
  items << Task.new(options)
end

#delete(item) ⇒ Object


18
19
20
# File 'lib/orchestration/queue.rb', line 18

def delete item
  @items.delete item
end

#empty?Boolean

Returns:

  • (Boolean)

34
35
36
# File 'lib/orchestration/queue.rb', line 34

def empty?
  items.empty?
end

#find_by_name(name) ⇒ Object


22
23
24
# File 'lib/orchestration/queue.rb', line 22

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

#to_jsonObject


42
43
44
# File 'lib/orchestration/queue.rb', line 42

def to_json
  all.to_json
end