ost 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +4 -2
- data/Rakefile +2 -1
- data/lib/ost.rb +3 -4
- data/ost.gemspec +4 -1
- data/test/ost_test.rb +36 -29
- data/test/test_helper.rb +1 -1
- metadata +29 -16
data/README.markdown
CHANGED
@@ -3,6 +3,8 @@ Ost
|
|
3
3
|
|
4
4
|
Redis based queues and workers.
|
5
5
|
|
6
|
+
![Ost Cafe, by Arancia Project](http://farm4.static.flickr.com/3255/3161710005_36566b8a9e.jpg)
|
7
|
+
|
6
8
|
Description
|
7
9
|
-----------
|
8
10
|
|
@@ -73,14 +75,14 @@ Differences with Delayed::Job and Resque
|
|
73
75
|
--------------------------------------
|
74
76
|
|
75
77
|
Both [Delayed::Job](http://github.com/tobi/delayed_job) and [Resque](http://github.com/defunkt/resque)
|
76
|
-
provide queues and workers (the
|
78
|
+
provide queues and workers (the latter using Redis). They provide dumb workers that process jobs, which are specialized for each task. The specialization takes place in the application side, and the job is serialized and pushed into a queue.
|
77
79
|
|
78
80
|
**Ost**, by contrast, just pushes numbers into specialized queues, and uses workers that are subscribed to specific queues and know what to do with the items they get. The total sum of logic is almost the same.
|
79
81
|
|
80
82
|
Installation
|
81
83
|
------------
|
82
84
|
|
83
|
-
$
|
85
|
+
$ gem install ost
|
84
86
|
|
85
87
|
License
|
86
88
|
-------
|
data/Rakefile
CHANGED
data/lib/ost.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
-
require "redis"
|
2
1
|
require "nest"
|
3
2
|
|
4
3
|
module Ost
|
5
|
-
VERSION = "0.0.
|
4
|
+
VERSION = "0.0.2"
|
6
5
|
TIMEOUT = ENV["OST_TIMEOUT"] || 2
|
7
6
|
|
8
7
|
class Queue
|
@@ -55,11 +54,11 @@ module Ost
|
|
55
54
|
end
|
56
55
|
|
57
56
|
def self.connect(options = {})
|
58
|
-
@redis = Redis.
|
57
|
+
@redis = Redis.connect(options)
|
59
58
|
end
|
60
59
|
|
61
60
|
def self.redis
|
62
|
-
@redis ||= Redis.
|
61
|
+
@redis ||= Redis.connect
|
63
62
|
end
|
64
63
|
|
65
64
|
def self.redis=(redis)
|
data/ost.gemspec
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "ost"
|
3
|
-
s.version = "0.0.
|
3
|
+
s.version = "0.0.2"
|
4
4
|
s.summary = "Redis based queues and workers."
|
5
5
|
s.description = "Ost lets you manage queues and workers with Redis."
|
6
6
|
s.authors = ["Michel Martens"]
|
7
7
|
s.email = ["michel@soveran.com"]
|
8
8
|
s.homepage = "http://github.com/soveran/ost"
|
9
9
|
s.files = ["LICENSE", "README.markdown", "Rakefile", "lib/ost.rb", "ost.gemspec", "test/ost_test.rb", "test/test_helper.rb"]
|
10
|
+
|
11
|
+
s.add_dependency "nest", "~> 1.0"
|
12
|
+
s.add_development_dependency "cutest", "~> 1.0"
|
10
13
|
end
|
data/test/ost_test.rb
CHANGED
@@ -1,63 +1,70 @@
|
|
1
|
-
require File.
|
1
|
+
require File.expand_path("test_helper", File.dirname(__FILE__))
|
2
2
|
|
3
|
-
|
3
|
+
scope do
|
4
4
|
def ost(&job)
|
5
5
|
thread = Thread.new do
|
6
|
+
Ost.redis = Redis.current
|
6
7
|
Ost[:events].each(&job)
|
7
8
|
end
|
8
9
|
|
9
|
-
sleep 0.
|
10
|
+
sleep 0.1
|
10
11
|
|
11
12
|
thread.kill
|
12
13
|
end
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
def enqueue(id)
|
16
|
+
Ost[:events].push(id)
|
17
|
+
end
|
17
18
|
|
18
|
-
|
19
|
-
Ost
|
19
|
+
prepare do
|
20
|
+
Ost.redis.flushall
|
20
21
|
end
|
21
22
|
|
22
|
-
|
23
|
-
|
23
|
+
setup do
|
24
|
+
Redis.new
|
24
25
|
end
|
25
26
|
|
26
|
-
|
27
|
-
|
27
|
+
test "insert items in the queue" do |redis|
|
28
|
+
enqueue(1)
|
29
|
+
assert_equal ["1"], redis.lrange("ost:events", 0, -1)
|
28
30
|
end
|
29
31
|
|
30
|
-
|
31
|
-
|
32
|
+
test "process items from the queue" do |redis|
|
33
|
+
enqueue(1)
|
34
|
+
|
35
|
+
results = []
|
32
36
|
|
33
37
|
ost do |item|
|
34
|
-
|
38
|
+
results << item
|
35
39
|
end
|
36
40
|
|
37
|
-
assert_equal [],
|
38
|
-
assert_equal ["1"],
|
41
|
+
assert_equal [], redis.lrange("ost:events", 0, -1)
|
42
|
+
assert_equal ["1"], results
|
39
43
|
end
|
40
44
|
|
41
|
-
|
45
|
+
test "add failures to special lists" do |redis|
|
46
|
+
enqueue(1)
|
47
|
+
|
42
48
|
ost do |item|
|
43
49
|
raise "Wrong answer"
|
44
50
|
end
|
45
51
|
|
46
|
-
assert_equal 0,
|
47
|
-
assert_equal 1,
|
52
|
+
assert_equal 0, redis.llen("ost:events")
|
53
|
+
assert_equal 1, redis.llen("ost:events:errors")
|
48
54
|
|
49
|
-
|
55
|
+
assert redis.rpop("ost:events:errors").match(/ost:events:1 => #<RuntimeError: Wrong answer/)
|
50
56
|
end
|
51
57
|
|
52
|
-
|
53
|
-
|
58
|
+
test "publish the error to a specific channel" do |redis|
|
59
|
+
enqueue(1)
|
60
|
+
results = []
|
54
61
|
|
55
62
|
t1 = Thread.new do
|
56
|
-
|
63
|
+
redis.subscribe("ost:events:errors") do |on|
|
57
64
|
on.message do |channel, message|
|
58
65
|
if message[/ost:events:1 => #<RuntimeError: Wrong answer/]
|
59
|
-
|
60
|
-
|
66
|
+
results << message
|
67
|
+
redis.unsubscribe
|
61
68
|
end
|
62
69
|
end
|
63
70
|
end
|
@@ -69,9 +76,9 @@ class TestOst < Test::Unit::TestCase
|
|
69
76
|
|
70
77
|
t1.kill
|
71
78
|
|
72
|
-
assert_equal 0,
|
73
|
-
assert_equal 1,
|
79
|
+
assert_equal 0, redis.llen("ost:events")
|
80
|
+
assert_equal 1, redis.llen("ost:events:errors")
|
74
81
|
|
75
|
-
|
82
|
+
assert results.pop.match(/ost:events:1 => #<RuntimeError: Wrong answer/)
|
76
83
|
end
|
77
84
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ost
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
version: 0.0.1
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.2
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
8
|
- Michel Martens
|
@@ -14,10 +10,30 @@ autorequire:
|
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
12
|
|
17
|
-
date:
|
18
|
-
|
19
|
-
|
20
|
-
|
13
|
+
date: 2011-04-12 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: nest
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ~>
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "1.0"
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: cutest
|
28
|
+
prerelease: false
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: "1.0"
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id002
|
21
37
|
description: Ost lets you manage queues and workers with Redis.
|
22
38
|
email:
|
23
39
|
- michel@soveran.com
|
@@ -35,7 +51,6 @@ files:
|
|
35
51
|
- ost.gemspec
|
36
52
|
- test/ost_test.rb
|
37
53
|
- test/test_helper.rb
|
38
|
-
has_rdoc: true
|
39
54
|
homepage: http://github.com/soveran/ost
|
40
55
|
licenses: []
|
41
56
|
|
@@ -45,23 +60,21 @@ rdoc_options: []
|
|
45
60
|
require_paths:
|
46
61
|
- lib
|
47
62
|
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
48
64
|
requirements:
|
49
65
|
- - ">="
|
50
66
|
- !ruby/object:Gem::Version
|
51
|
-
segments:
|
52
|
-
- 0
|
53
67
|
version: "0"
|
54
68
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
55
70
|
requirements:
|
56
71
|
- - ">="
|
57
72
|
- !ruby/object:Gem::Version
|
58
|
-
segments:
|
59
|
-
- 0
|
60
73
|
version: "0"
|
61
74
|
requirements: []
|
62
75
|
|
63
76
|
rubyforge_project:
|
64
|
-
rubygems_version: 1.
|
77
|
+
rubygems_version: 1.7.2
|
65
78
|
signing_key:
|
66
79
|
specification_version: 3
|
67
80
|
summary: Redis based queues and workers.
|