ost 0.0.2 → 0.0.3
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.
- data/lib/ost.rb +18 -10
- data/ost.gemspec +12 -2
- data/test/ost_test.rb +29 -3
- data/test/test_helper.rb +3 -0
- metadata +3 -3
data/lib/ost.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "nest"
|
2
2
|
|
3
3
|
module Ost
|
4
|
-
VERSION = "0.0.
|
4
|
+
VERSION = "0.0.3"
|
5
5
|
TIMEOUT = ENV["OST_TIMEOUT"] || 2
|
6
6
|
|
7
7
|
class Queue
|
@@ -16,7 +16,11 @@ module Ost
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def each(&block)
|
19
|
+
@stopping = false
|
20
|
+
|
19
21
|
loop do
|
22
|
+
break if @stopping
|
23
|
+
|
20
24
|
_, item = redis.brpop(ns, TIMEOUT)
|
21
25
|
next if item.nil? or item.empty?
|
22
26
|
|
@@ -35,13 +39,15 @@ module Ost
|
|
35
39
|
redis.lrange ns[:errors], 0, -1
|
36
40
|
end
|
37
41
|
|
42
|
+
def stop
|
43
|
+
@stopping = true
|
44
|
+
end
|
45
|
+
|
38
46
|
alias << push
|
39
47
|
alias pop each
|
40
48
|
|
41
|
-
private
|
42
|
-
|
43
49
|
def redis
|
44
|
-
Ost.
|
50
|
+
@redis ||= Redis.connect(Ost.options)
|
45
51
|
end
|
46
52
|
end
|
47
53
|
|
@@ -53,15 +59,17 @@ module Ost
|
|
53
59
|
@queues[queue]
|
54
60
|
end
|
55
61
|
|
56
|
-
def self.
|
57
|
-
@
|
62
|
+
def self.stop
|
63
|
+
@queues.each { |_, queue| queue.stop }
|
58
64
|
end
|
59
65
|
|
60
|
-
|
61
|
-
|
66
|
+
@options = nil
|
67
|
+
|
68
|
+
def self.connect(options = {})
|
69
|
+
@options = options
|
62
70
|
end
|
63
71
|
|
64
|
-
def self.
|
65
|
-
@
|
72
|
+
def self.options
|
73
|
+
@options || {}
|
66
74
|
end
|
67
75
|
end
|
data/ost.gemspec
CHANGED
@@ -1,12 +1,22 @@
|
|
1
|
+
require "./lib/ost"
|
2
|
+
|
1
3
|
Gem::Specification.new do |s|
|
2
4
|
s.name = "ost"
|
3
|
-
s.version =
|
5
|
+
s.version = Ost::VERSION
|
4
6
|
s.summary = "Redis based queues and workers."
|
5
7
|
s.description = "Ost lets you manage queues and workers with Redis."
|
6
8
|
s.authors = ["Michel Martens"]
|
7
9
|
s.email = ["michel@soveran.com"]
|
8
10
|
s.homepage = "http://github.com/soveran/ost"
|
9
|
-
|
11
|
+
|
12
|
+
s.files = Dir[
|
13
|
+
"LICENSE",
|
14
|
+
"README.markdown",
|
15
|
+
"Rakefile",
|
16
|
+
"lib/**/*.rb",
|
17
|
+
"*.gemspec",
|
18
|
+
"test/*.*"
|
19
|
+
]
|
10
20
|
|
11
21
|
s.add_dependency "nest", "~> 1.0"
|
12
22
|
s.add_development_dependency "cutest", "~> 1.0"
|
data/test/ost_test.rb
CHANGED
@@ -3,7 +3,6 @@ require File.expand_path("test_helper", File.dirname(__FILE__))
|
|
3
3
|
scope do
|
4
4
|
def ost(&job)
|
5
5
|
thread = Thread.new do
|
6
|
-
Ost.redis = Redis.current
|
7
6
|
Ost[:events].each(&job)
|
8
7
|
end
|
9
8
|
|
@@ -17,10 +16,11 @@ scope do
|
|
17
16
|
end
|
18
17
|
|
19
18
|
prepare do
|
20
|
-
|
19
|
+
Redis.current.flushall
|
21
20
|
end
|
22
21
|
|
23
22
|
setup do
|
23
|
+
Ost[:events].redis.quit
|
24
24
|
Redis.new
|
25
25
|
end
|
26
26
|
|
@@ -74,11 +74,37 @@ scope do
|
|
74
74
|
raise "Wrong answer"
|
75
75
|
end
|
76
76
|
|
77
|
-
t1.
|
77
|
+
t1.join
|
78
78
|
|
79
79
|
assert_equal 0, redis.llen("ost:events")
|
80
80
|
assert_equal 1, redis.llen("ost:events:errors")
|
81
81
|
|
82
82
|
assert results.pop.match(/ost:events:1 => #<RuntimeError: Wrong answer/)
|
83
83
|
end
|
84
|
+
|
85
|
+
test "halt processing a queue" do
|
86
|
+
Thread.new do
|
87
|
+
sleep 0.5
|
88
|
+
Ost[:always_empty].stop
|
89
|
+
end
|
90
|
+
|
91
|
+
Ost[:always_empty].each { }
|
92
|
+
|
93
|
+
assert true
|
94
|
+
end
|
95
|
+
|
96
|
+
test "halt processing all queues" do
|
97
|
+
Thread.new do
|
98
|
+
sleep 0.5
|
99
|
+
Ost.stop
|
100
|
+
end
|
101
|
+
|
102
|
+
t1 = Thread.new { Ost[:always_empty].each { } }
|
103
|
+
t2 = Thread.new { Ost[:always_empty_too].each { } }
|
104
|
+
|
105
|
+
t1.join
|
106
|
+
t2.join
|
107
|
+
|
108
|
+
assert true
|
109
|
+
end
|
84
110
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: ost
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Michel Martens
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-05-13 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: nest
|
@@ -74,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
74
|
requirements: []
|
75
75
|
|
76
76
|
rubyforge_project:
|
77
|
-
rubygems_version: 1.
|
77
|
+
rubygems_version: 1.8.1
|
78
78
|
signing_key:
|
79
79
|
specification_version: 3
|
80
80
|
summary: Redis based queues and workers.
|