kanban 0.3.1 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1269e09e1ed2b1e5fe61f15a0bc6afca6de16fe4
4
- data.tar.gz: 5a9d91b4fa9422ad18b3dddfb9d7586f01db9085
3
+ metadata.gz: 5571f4ff8d96226cd84855428ad20f875669991f
4
+ data.tar.gz: 3ef547ba9f47b0dd43ef43e851052848374e8197
5
5
  SHA512:
6
- metadata.gz: 4294deecdd8f137be52fc4478815b2d65fcf0d2f4b583d78831ff166c95fe1794235f81b6f813a13845775ee08bc96c52d9a93a0522900b9989825d0f4fa5dfe
7
- data.tar.gz: 1bd3f95ede9394a0f93d15a3c722b6d91ffefae87be9f59bc325aa001d71480e8a01235ba0fdeed24bd4f7c503d436517c4ae56119d972c5b0ec425a022e0a0d
6
+ metadata.gz: fbf31b07bfbbcc2a3fd32d4096c0a082c52d880eca58fd7cd041d3deee1f2ebab7448ba1a94eac68c8fb0ac9967ac5d2b42e45fc0102b1b25d1e00364937e2ee
7
+ data.tar.gz: 08a57add1ad3040481c6ce516ed90ecbbccf2df861038f311f82fec3e3e0557c9e49497c2f69d4d85730e095c3349ee50cbb1e8dfbfd1bbc61488be127a00855
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.5.1
data/kanban.gemspec CHANGED
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: kanban 0.3.1 ruby lib
5
+ # stub: kanban 0.5.1 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "kanban"
9
- s.version = "0.3.1"
9
+ s.version = "0.5.1"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Chris Olstrom"]
14
- s.date = "2015-05-26"
14
+ s.date = "2015-05-28"
15
15
  s.description = "Because your code totally needed an Agile Workflow"
16
16
  s.email = "chris@olstrom.com"
17
17
  s.extra_rdoc_files = [
data/lib/kanban.rb CHANGED
@@ -10,7 +10,7 @@ module Kanban
10
10
  def initialize(backend:, **options)
11
11
  @namespace = options.fetch :namespace, 'default'
12
12
  @queue = "#{@namespace}:#{options.fetch :queue, 'tasks'}"
13
- @item = "#{@namespace}:#{options.fetch :item, 'tasks'}"
13
+ @item = "#{@namespace}:#{options.fetch :item, 'task'}"
14
14
  @backend = backend
15
15
  end
16
16
 
@@ -38,5 +38,27 @@ module Kanban
38
38
  safe = task.with_string_keys
39
39
  add(safe)
40
40
  end
41
+
42
+ def claim(duration: 3)
43
+ id = @backend.brpoplpush("#{@queue}:todo", "#{@queue}:doing")
44
+ @backend.set "#{@item}:#{id}:claimed", true, ex: duration
45
+ id.to_i
46
+ end
47
+
48
+ def claimed?(id)
49
+ @backend.exists "#{@item}:#{id}:claimed"
50
+ end
51
+
52
+ def doing
53
+ @backend.lrange("#{@queue}:doing", 0, -1).map(&:to_i)
54
+ end
55
+
56
+ def complete(id)
57
+ @backend.setbit("#{@queue}:completed", id, 1).zero?
58
+ end
59
+
60
+ def completed?(id)
61
+ @backend.getbit("#{@queue}:completed", id) == 1
62
+ end
41
63
  end
42
64
  end
data/spec/kanban_spec.rb CHANGED
@@ -1,29 +1,32 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require 'timeout'
2
3
 
3
4
  describe 'Backlog' do
4
5
  before do
5
- @backlog = Kanban::Backlog.new backend: Redis.new
6
+ @backlog = Kanban::Backlog.new backend: Redis.new, namespace: 'kanban:test'
6
7
  end
7
8
 
8
- it 'instantiates without error' do
9
- expect(@backlog).to be_an_instance_of(Kanban::Backlog)
9
+ after(:all) do
10
+ redis = Redis.new
11
+ redis.keys('kanban:test:*').each do |key|
12
+ redis.del key
13
+ end
10
14
  end
11
15
 
12
- it 'should have a namespace' do
13
- expect(@backlog.namespace).to eq 'default'
16
+ it 'instantiates without error' do
17
+ expect(@backlog).to be_an_instance_of(Kanban::Backlog)
14
18
  end
15
19
 
16
20
  it 'should allow namespace configuration at initialization' do
17
- backlog = Kanban::Backlog.new namespace: 'foo', backend: nil
18
- expect(backlog.namespace).to eq 'foo'
21
+ expect(@backlog.namespace).to eq 'kanban:test'
19
22
  end
20
23
 
21
24
  it 'should prefix queue keys with the namespace' do
22
- expect(@backlog.queue).to start_with('default')
25
+ expect(@backlog.queue).to start_with('kanban:test')
23
26
  end
24
27
 
25
28
  it 'should prefix item keys with the namespace' do
26
- expect(@backlog.item).to start_with('default')
29
+ expect(@backlog.item).to start_with('kanban:test')
27
30
  end
28
31
 
29
32
  it 'should require a backend' do
@@ -71,4 +74,55 @@ describe 'Backlog' do
71
74
  id = @backlog.add(task)
72
75
  expect(@backlog.todo).to include(id)
73
76
  end
77
+
78
+ it 'should allow a task to be claimed' do
79
+ expect(@backlog.claim).to be_a Fixnum
80
+ end
81
+
82
+ it 'should track the claim separately from the queue it is in' do
83
+ id = @backlog.claim
84
+ redis = Redis.new
85
+ expect(redis.exists("#{@backlog.item}:#{id}:claimed")).to be true
86
+ end
87
+
88
+ it 'should allow claims to expire' do
89
+ id = @backlog.claim(duration: 1)
90
+ sleep 1.1
91
+ redis = Redis.new
92
+ expect(redis.exists("#{@backlog.item}:#{id}:claimed")).to be false
93
+ end
94
+
95
+ it 'should block if there are no pending tasks' do
96
+ redis = Redis.new
97
+ redis.del "#{@backlog.queue}:todo"
98
+ expect do
99
+ Timeout.timeout(0.1) do
100
+ @backlog.claim
101
+ end
102
+ end.to raise_error(Timeout::Error)
103
+ end
104
+
105
+ it 'should report if a task is claimed' do
106
+ task = { 'test' => 'data' }
107
+ 5.times { @backlog.add(task) }
108
+ id = @backlog.claim
109
+ expect(@backlog.claimed?(id)).to be true
110
+ expect(@backlog.claimed?(0)).to be false
111
+ end
112
+
113
+ it 'should have a list of tasks being worked on' do
114
+ id = @backlog.claim
115
+ expect(@backlog.doing).to include(id)
116
+ end
117
+
118
+ it 'should allow indicating completion of a task only once' do
119
+ expect(@backlog.complete(1)).to be true
120
+ expect(@backlog.complete(1)).to be false
121
+ end
122
+
123
+ it 'should check if a task is completed' do
124
+ expect(@backlog.completed?(2)).to be false
125
+ @backlog.complete 2
126
+ expect(@backlog.completed?(2)).to be true
127
+ end
74
128
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kanban
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Olstrom
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-26 00:00:00.000000000 Z
11
+ date: 2015-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis