stubborn_queue 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +22 -1
- data/lib/stubborn_queue.rb +2 -1
- data/stubborn_queue.gemspec +1 -1
- data/test/queueing_spec.rb +6 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 90d2f50ebe095942f263c570074d6d874accd2ab
|
4
|
+
data.tar.gz: ef596e963efd4eb7af78db84bad371be416cefe5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7363f71ae7068065e8fb30f17fffeaf2249708dbfd20404e56b193624637f1cb22f3ddb2288c0881961ba259598a04af2908c4a8c9f35352d98b968f8a1e7792
|
7
|
+
data.tar.gz: d26598c7182860bd7550a27c21d25c3b5b4c0929ad7025463e4e0e4f0af3905569b3710b7e75adbcafe4c3aca4816ad190968839cf17acaa5b192c64426ca644
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,3 +1,24 @@
|
|
1
|
+
# stubborn_queue
|
2
|
+
|
3
|
+
Sometimes you want to make sure that stuff on your queue gets done. This stubborn queue will insist that something isn't done until you tell it otherwise. Unfinished items get requeued after a specified amount of time because you didn't do it right. I store the data in file to avoid dependencies outside of Ruby itself.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
important_data = StubbornQueue.new name: 'important_data', timeout: 60
|
9
|
+
length = important_data.enqueue 'top secret!'
|
10
|
+
id = important_data.dequeue
|
11
|
+
data = important_data.lookup id
|
12
|
+
do_something_with data
|
13
|
+
important_data.finish id
|
14
|
+
```
|
15
|
+
|
16
|
+
If `do_something_with` takes longer than 60 seconds, it'll assume that you crashed out and requeue it for another worker.
|
17
|
+
|
18
|
+
## Heads up!
|
19
|
+
|
1
20
|
This is in no way inherently thread- or process-safe. It's built for one process owning one queue file and not interacting with it asynchronously.
|
2
21
|
|
3
|
-
|
22
|
+
## Special thanks
|
23
|
+
|
24
|
+
Huge props to [Chris Olstrom](https://github.com/colstrom) who helped me understand the idea and was a good sport when I made my own implementation which will probably be extremely similar to his.
|
data/lib/stubborn_queue.rb
CHANGED
@@ -7,7 +7,8 @@ class StubbornQueue
|
|
7
7
|
def initialize(options = {})
|
8
8
|
@name = options.fetch :name, 'default'
|
9
9
|
@timeout = options.fetch :timeout, 60
|
10
|
-
|
10
|
+
path = options.fetch :file, ".#{@name}.db"
|
11
|
+
@db = Moneta.new :Daybreak, expires: true, file: path
|
11
12
|
end
|
12
13
|
|
13
14
|
def key_for(type, with_id: 0)
|
data/stubborn_queue.gemspec
CHANGED
data/test/queueing_spec.rb
CHANGED
@@ -5,7 +5,8 @@ require 'stubborn_queue'
|
|
5
5
|
context 'queueing' do
|
6
6
|
setup do
|
7
7
|
@timeout = 1
|
8
|
-
@
|
8
|
+
@path = '/tmp/.testing'
|
9
|
+
@queue = StubbornQueue.new name: 'test', timeout: @timeout, file: @path
|
9
10
|
@queue.db.clear
|
10
11
|
@item = 'test_item'
|
11
12
|
end
|
@@ -30,4 +31,8 @@ context 'queueing' do
|
|
30
31
|
sleep (@timeout+1)
|
31
32
|
assert_equal 1, @queue.enqueue(@item)
|
32
33
|
end
|
34
|
+
|
35
|
+
should 'place the DB file at the specified path' do
|
36
|
+
assert_equal true, File.exists?(@path)
|
37
|
+
end
|
33
38
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stubborn_queue
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Scott
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|