requeue 0.7.3 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +14 -3
- data/lib/requeue.rb +5 -5
- data/lib/requeue/version.rb +1 -1
- data/spec/requeue_spec.rb +32 -32
- metadata +2 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 803325213f9e3e8321146cc00588381e9158396d
|
4
|
+
data.tar.gz: f39280e72b3cd3bb7a396cb4b7a1c9c893990017
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b48342b8ec4015a90f968bd49d581c2fb422a8106c4b3a6599680ca46e1a15d76e2b5e2972429062c9343203a0fe08294eb5538bb94a64f465a29861d17b72c8
|
7
|
+
data.tar.gz: 5095055ac1b0c8aa0e07cd9857788970f1f0db20863424b734e34569feb38413c00a43f47f91bea5c9c3421641dd59cc4ba491d2529ef3ede8819b48b88df358
|
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# Requeue
|
2
2
|
[](https://codeclimate.com/github/lumoslabs/requeue)
|
3
|
+
|
4
|
+
[](https://circleci.com/gh/lumoslabs/requeue)
|
5
|
+
|
3
6
|
Requeue is a rediciulosly simple queue backed by redis.
|
4
7
|
|
5
8
|
## Installation
|
@@ -46,28 +49,36 @@ q.clear!
|
|
46
49
|
q.steal!
|
47
50
|
|
48
51
|
#To get the position of a value
|
49
|
-
q.position('thing')
|
52
|
+
q.position('thing')
|
53
|
+
=> 0
|
50
54
|
|
51
55
|
#To see if an item is queued
|
52
|
-
q.queued?('thing')
|
56
|
+
q.queued?('thing')
|
57
|
+
=> true
|
53
58
|
|
54
59
|
#To see the the current first item of the queue
|
55
|
-
q.owner
|
60
|
+
q.owner
|
61
|
+
=> 'thing'
|
56
62
|
|
57
63
|
#To get the queue as a hash
|
58
64
|
q.as_hash
|
65
|
+
=> {:queue => ['1','2','3'] :owned => true :length => 3}
|
59
66
|
|
60
67
|
#To get the queue as a json blob
|
61
68
|
q.as_json
|
69
|
+
=> '{"queue": [1,2,3], "owned" : true, "length": 3 }'
|
62
70
|
|
63
71
|
#To get the internal name of the queue
|
64
72
|
q.name
|
73
|
+
=> 'awesome:queue'
|
65
74
|
|
66
75
|
#To get the length of the queue
|
67
76
|
q.length
|
77
|
+
=> 3
|
68
78
|
|
69
79
|
#To get all of the items in the queue
|
70
80
|
q.list
|
81
|
+
=> [1,2,3]
|
71
82
|
```
|
72
83
|
|
73
84
|
## Contributing
|
data/lib/requeue.rb
CHANGED
@@ -20,11 +20,11 @@ module Requeue
|
|
20
20
|
@redis.llen(name)
|
21
21
|
end
|
22
22
|
|
23
|
-
def clear
|
23
|
+
def clear
|
24
24
|
@redis.del(name)
|
25
25
|
end
|
26
26
|
|
27
|
-
def enqueue
|
27
|
+
def enqueue(value)
|
28
28
|
if (@unique == false || !queued?(value))
|
29
29
|
@redis.rpush(name, value)
|
30
30
|
else
|
@@ -32,7 +32,7 @@ module Requeue
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
def dequeue
|
35
|
+
def dequeue
|
36
36
|
@redis.lpop(name)
|
37
37
|
end
|
38
38
|
|
@@ -44,7 +44,7 @@ module Requeue
|
|
44
44
|
list.index(value)
|
45
45
|
end
|
46
46
|
|
47
|
-
def remove
|
47
|
+
def remove(value)
|
48
48
|
@redis.lrem(name, 0, value)
|
49
49
|
end
|
50
50
|
|
@@ -60,7 +60,7 @@ module Requeue
|
|
60
60
|
length > 0
|
61
61
|
end
|
62
62
|
|
63
|
-
def steal
|
63
|
+
def steal(value)
|
64
64
|
@redis.lpush(name, value)
|
65
65
|
end
|
66
66
|
|
data/lib/requeue/version.rb
CHANGED
data/spec/requeue_spec.rb
CHANGED
@@ -6,48 +6,48 @@ describe Requeue::Queue do
|
|
6
6
|
end
|
7
7
|
|
8
8
|
after(:each) do
|
9
|
-
@queue.clear
|
9
|
+
@queue.clear
|
10
10
|
end
|
11
11
|
|
12
12
|
describe '.name' do
|
13
13
|
it { expect(@queue.name).to eq("test:queue") }
|
14
14
|
end
|
15
15
|
|
16
|
-
describe '.clear
|
17
|
-
before { @queue.enqueue
|
16
|
+
describe '.clear' do
|
17
|
+
before { @queue.enqueue('eric') }
|
18
18
|
|
19
19
|
it 'should empty the queue' do
|
20
|
-
expect{ @queue.clear
|
20
|
+
expect{ @queue.clear }.to change { @queue.length }.from(1).to(0)
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'should see an empty queue' do
|
24
|
-
expect {@queue.clear
|
24
|
+
expect {@queue.clear }.to change { @queue.owned? }.from(true).to(false)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
28
|
describe '.enqueue' do
|
29
29
|
context 'when no users are enqueued' do
|
30
30
|
it 'returns the number of users in the queue' do
|
31
|
-
expect(@queue.enqueue
|
31
|
+
expect(@queue.enqueue('eric')).to eq(1)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
35
|
context 'when some users are enqueued' do
|
36
|
-
before { @queue.enqueue
|
37
|
-
before { @queue.enqueue
|
36
|
+
before { @queue.enqueue('bob') }
|
37
|
+
before { @queue.enqueue('eric') }
|
38
38
|
it 'should have a length of 2' do
|
39
39
|
expect(@queue.length).to eq(2)
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'should only add the user to the queue if it is unique' do
|
43
|
-
expect(@queue.enqueue
|
43
|
+
expect(@queue.enqueue('eric')).to eq(2)
|
44
44
|
expect(@queue.length).to eq(2)
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'should add non-unique values if the queue is set to non-unique' do
|
48
48
|
nonunique = Requeue::Queue.new(unique:false)
|
49
|
-
nonunique.enqueue
|
50
|
-
expect{ nonunique.enqueue
|
49
|
+
nonunique.enqueue('eric')
|
50
|
+
expect{ nonunique.enqueue('eric') }.to change { nonunique.length }.from(1).to(2)
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
@@ -60,8 +60,8 @@ describe Requeue::Queue do
|
|
60
60
|
end
|
61
61
|
|
62
62
|
context 'when some users are enqueued' do
|
63
|
-
before { @queue.enqueue
|
64
|
-
before { @queue.enqueue
|
63
|
+
before { @queue.enqueue('bob') }
|
64
|
+
before { @queue.enqueue('eric') }
|
65
65
|
|
66
66
|
it 'should have the current users' do
|
67
67
|
expect(@queue.list).to eq(['bob', 'eric'])
|
@@ -70,8 +70,8 @@ describe Requeue::Queue do
|
|
70
70
|
end
|
71
71
|
|
72
72
|
describe '.user_queued?' do
|
73
|
-
before { @queue.enqueue
|
74
|
-
before { @queue.enqueue
|
73
|
+
before { @queue.enqueue('bob') }
|
74
|
+
before { @queue.enqueue('eric') }
|
75
75
|
|
76
76
|
it 'should show eric as queued' do
|
77
77
|
expect(@queue.queued? 'eric').to eq(true)
|
@@ -87,8 +87,8 @@ describe Requeue::Queue do
|
|
87
87
|
end
|
88
88
|
|
89
89
|
describe '.user_position' do
|
90
|
-
before { @queue.enqueue
|
91
|
-
before { @queue.enqueue
|
90
|
+
before { @queue.enqueue('bob') }
|
91
|
+
before { @queue.enqueue('eric') }
|
92
92
|
|
93
93
|
it 'eric should be in position 1 (the second place)' do
|
94
94
|
expect(@queue.position 'eric').to eq(1)
|
@@ -97,11 +97,11 @@ describe Requeue::Queue do
|
|
97
97
|
end
|
98
98
|
|
99
99
|
describe '.dequeue' do
|
100
|
-
before { @queue.enqueue
|
101
|
-
before { @queue.enqueue
|
100
|
+
before { @queue.enqueue('bob') }
|
101
|
+
before { @queue.enqueue('eric') }
|
102
102
|
|
103
103
|
it 'eric should be in position 1 (the second place)' do
|
104
|
-
expect{ @queue.dequeue
|
104
|
+
expect{ @queue.dequeue }.to change {@queue.position 'eric'}.from(1).to(0)
|
105
105
|
end
|
106
106
|
end
|
107
107
|
|
@@ -113,33 +113,33 @@ describe Requeue::Queue do
|
|
113
113
|
end
|
114
114
|
|
115
115
|
context 'when a user is enqueued' do
|
116
|
-
before { @queue.enqueue
|
116
|
+
before { @queue.enqueue('eric') }
|
117
117
|
it 'should be owned' do
|
118
118
|
expect(@queue.owner).to eq('eric')
|
119
119
|
end
|
120
120
|
end
|
121
121
|
end
|
122
122
|
|
123
|
-
describe '.remove
|
124
|
-
before { @queue.enqueue
|
125
|
-
before { @queue.enqueue
|
123
|
+
describe '.remove' do
|
124
|
+
before { @queue.enqueue('bob') }
|
125
|
+
before { @queue.enqueue('eric') }
|
126
126
|
|
127
127
|
it 'should not contain eric anymore' do
|
128
|
-
expect { @queue.remove
|
129
|
-
expect { @queue.remove
|
128
|
+
expect { @queue.remove('eric') }.to change {@queue.queued?('eric')}
|
129
|
+
expect { @queue.remove('eric') }.to_not change {@queue.queued?('bob')}
|
130
130
|
end
|
131
131
|
end
|
132
132
|
|
133
|
-
describe '.steal
|
134
|
-
before { @queue.enqueue
|
135
|
-
before { @queue.enqueue
|
133
|
+
describe '.steal' do
|
134
|
+
before { @queue.enqueue('bob') }
|
135
|
+
before { @queue.enqueue('eric') }
|
136
136
|
|
137
137
|
it 'jim should own the queue' do
|
138
|
-
expect { @queue.steal
|
138
|
+
expect { @queue.steal('jim') }.to change { @queue.owner }.from('bob').to('jim')
|
139
139
|
end
|
140
140
|
|
141
141
|
it 'the queue should still have everyone else in it' do
|
142
|
-
expect { @queue.steal
|
142
|
+
expect { @queue.steal('jim') }.to change { @queue.length }.from(2).to(3)
|
143
143
|
end
|
144
144
|
end
|
145
145
|
|
@@ -152,7 +152,7 @@ describe Requeue::Queue do
|
|
152
152
|
|
153
153
|
context 'when a user is enqueued' do
|
154
154
|
it 'should be owned' do
|
155
|
-
expect { @queue.enqueue
|
155
|
+
expect { @queue.enqueue('eric') }.to change { @queue.owned? }
|
156
156
|
end
|
157
157
|
end
|
158
158
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: requeue
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Fode
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -55,7 +55,6 @@ files:
|
|
55
55
|
- lib/requeue.rb
|
56
56
|
- lib/requeue/version.rb
|
57
57
|
- requeue.gemspec
|
58
|
-
- spec/.requeue_spec.rb.swp
|
59
58
|
- spec/requeue_spec.rb
|
60
59
|
- spec/spec_helper.rb
|
61
60
|
- spec/support/fakeredis.rb
|
@@ -84,7 +83,6 @@ signing_key:
|
|
84
83
|
specification_version: 4
|
85
84
|
summary: A simple resque based queue
|
86
85
|
test_files:
|
87
|
-
- spec/.requeue_spec.rb.swp
|
88
86
|
- spec/requeue_spec.rb
|
89
87
|
- spec/spec_helper.rb
|
90
88
|
- spec/support/fakeredis.rb
|