Class: Kanban::Backlog
Instance Attribute Summary collapse
-
#item ⇒ Object
readonly
Returns the value of attribute item.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
Instance Method Summary collapse
- #add(task) ⇒ Object
- #add!(task) ⇒ Object
- #claim(duration: 3) ⇒ Object
- #claimed?(id) ⇒ Boolean
- #complete(id) ⇒ Object
- #completed?(id) ⇒ Boolean
- #doing ⇒ Object
- #done?(id) ⇒ Boolean
- #expire_claim(id) ⇒ Object
- #get(id) ⇒ Object
- #groom ⇒ Object
-
#initialize(backend:, **options) ⇒ Backlog
constructor
A new instance of Backlog.
- #next_id ⇒ Object
- #release(id) ⇒ Object
- #requeue(id) ⇒ Object
- #todo ⇒ Object
- #unworkable(id) ⇒ Object
- #unworkable?(id) ⇒ Boolean
Constructor Details
#initialize(backend:, **options) ⇒ Backlog
Returns a new instance of Backlog.
12 13 14 15 16 17 |
# File 'lib/kanban.rb', line 12 def initialize(backend:, **) @namespace = .fetch :namespace, 'default' @queue = "#{@namespace}:#{.fetch :queue, 'tasks'}" @item = "#{@namespace}:#{.fetch :item, 'task'}" @backend = backend end |
Instance Attribute Details
#item ⇒ Object (readonly)
Returns the value of attribute item.
10 11 12 |
# File 'lib/kanban.rb', line 10 def item @item end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
10 11 12 |
# File 'lib/kanban.rb', line 10 def namespace @namespace end |
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
10 11 12 |
# File 'lib/kanban.rb', line 10 def queue @queue end |
Instance Method Details
#add(task) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/kanban.rb', line 35 def add(task) id = next_id @backend.hmset "#{@item}:#{id}", *task.to_a @backend.lpush "#{@queue}:todo", id id end |
#add!(task) ⇒ Object
43 44 45 46 |
# File 'lib/kanban.rb', line 43 def add!(task) safe = task.with_string_keys add(safe) end |
#claim(duration: 3) ⇒ Object
49 50 51 52 53 |
# File 'lib/kanban.rb', line 49 def claim(duration: 3) id = @backend.brpoplpush("#{@queue}:todo", "#{@queue}:doing") @backend.set "#{@item}:#{id}:claimed", true, ex: duration id.to_i end |
#claimed?(id) ⇒ Boolean
56 57 58 |
# File 'lib/kanban.rb', line 56 def claimed?(id) @backend.exists "#{@item}:#{id}:claimed" end |
#complete(id) ⇒ Object
66 67 68 |
# File 'lib/kanban.rb', line 66 def complete(id) @backend.setbit("#{@queue}:completed", id, 1).zero? end |
#completed?(id) ⇒ Boolean
71 72 73 |
# File 'lib/kanban.rb', line 71 def completed?(id) @backend.getbit("#{@queue}:completed", id) == 1 end |
#doing ⇒ Object
61 62 63 |
# File 'lib/kanban.rb', line 61 def doing @backend.lrange("#{@queue}:doing", 0, -1).map(&:to_i) end |
#done?(id) ⇒ Boolean
86 87 88 |
# File 'lib/kanban.rb', line 86 def done?(id) completed?(id) || unworkable?(id) end |
#expire_claim(id) ⇒ Object
97 98 99 |
# File 'lib/kanban.rb', line 97 def expire_claim(id) @backend.expire "#{@item}:#{id}:claimed", 0 end |
#get(id) ⇒ Object
20 21 22 |
# File 'lib/kanban.rb', line 20 def get(id) @backend.hgetall "#{@item}:#{id}" end |
#groom ⇒ Object
108 109 110 111 112 113 114 115 116 117 |
# File 'lib/kanban.rb', line 108 def groom doing.map do |id| next if claimed? id if done? id id if release id else id if requeue id end end.compact end |
#next_id ⇒ Object
25 26 27 |
# File 'lib/kanban.rb', line 25 def next_id @backend.incr "#{@queue}:id" end |
#release(id) ⇒ Object
91 92 93 94 |
# File 'lib/kanban.rb', line 91 def release(id) expire_claim id @backend.lrem("#{@queue}:doing", 0, id) > 0 end |
#requeue(id) ⇒ Object
102 103 104 105 |
# File 'lib/kanban.rb', line 102 def requeue(id) release id @backend.lpush("#{@queue}:todo", id) > 0 end |
#todo ⇒ Object
30 31 32 |
# File 'lib/kanban.rb', line 30 def todo @backend.lrange("#{@queue}:todo", 0, -1).map(&:to_i) end |
#unworkable(id) ⇒ Object
76 77 78 |
# File 'lib/kanban.rb', line 76 def unworkable(id) @backend.setbit("#{@queue}:unworkable", id, 1).zero? end |
#unworkable?(id) ⇒ Boolean
81 82 83 |
# File 'lib/kanban.rb', line 81 def unworkable?(id) @backend.getbit("#{@queue}:unworkable", id) == 1 end |