qu-redis 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/qu/backend/redis.rb +29 -19
- metadata +44 -76
data/lib/qu/backend/redis.rb
CHANGED
@@ -15,12 +15,13 @@ module Qu
|
|
15
15
|
end
|
16
16
|
alias_method :redis, :connection
|
17
17
|
|
18
|
-
def enqueue(
|
19
|
-
|
20
|
-
redis.set("job:#{
|
21
|
-
redis.rpush("queue:#{
|
22
|
-
redis.sadd('queues',
|
23
|
-
job
|
18
|
+
def enqueue(payload)
|
19
|
+
payload.id = SimpleUUID::UUID.new.to_guid
|
20
|
+
redis.set("job:#{payload.id}", encode('klass' => payload.klass.to_s, 'args' => payload.args))
|
21
|
+
redis.rpush("queue:#{payload.queue}", payload.id)
|
22
|
+
redis.sadd('queues', payload.queue)
|
23
|
+
logger.debug { "Enqueued job #{payload}" }
|
24
|
+
payload
|
24
25
|
end
|
25
26
|
|
26
27
|
def length(queue = 'default')
|
@@ -29,7 +30,9 @@ module Qu
|
|
29
30
|
|
30
31
|
def clear(queue = nil)
|
31
32
|
queue ||= queues + ['failed']
|
33
|
+
logger.info { "Clearing queues: #{queue.inspect}" }
|
32
34
|
Array(queue).each do |q|
|
35
|
+
logger.debug "Clearing queue #{q}"
|
33
36
|
redis.srem('queues', q)
|
34
37
|
redis.del("queue:#{q}")
|
35
38
|
end
|
@@ -42,6 +45,8 @@ module Qu
|
|
42
45
|
def reserve(worker, options = {:block => true})
|
43
46
|
queues = worker.queues.map {|q| "queue:#{q}" }
|
44
47
|
|
48
|
+
logger.debug { "Reserving job in queues #{queues.inspect}"}
|
49
|
+
|
45
50
|
if options[:block]
|
46
51
|
id = redis.blpop(*queues.push(0))[1]
|
47
52
|
else
|
@@ -51,36 +56,39 @@ module Qu
|
|
51
56
|
get(id) if id
|
52
57
|
end
|
53
58
|
|
54
|
-
def release(
|
55
|
-
redis.rpush("queue:#{
|
59
|
+
def release(payload)
|
60
|
+
redis.rpush("queue:#{payload.queue}", payload.id)
|
56
61
|
end
|
57
62
|
|
58
|
-
def failed(
|
59
|
-
redis.rpush("queue:failed",
|
63
|
+
def failed(payload, error)
|
64
|
+
redis.rpush("queue:failed", payload.id)
|
60
65
|
end
|
61
66
|
|
62
|
-
def completed(
|
63
|
-
redis.del("job:#{
|
67
|
+
def completed(payload)
|
68
|
+
redis.del("job:#{payload.id}")
|
64
69
|
end
|
65
70
|
|
66
71
|
def requeue(id)
|
67
|
-
|
72
|
+
logger.debug "Requeuing job #{id}"
|
73
|
+
if payload = get(id)
|
68
74
|
redis.lrem('queue:failed', 1, id)
|
69
|
-
redis.rpush("queue:#{
|
70
|
-
|
75
|
+
redis.rpush("queue:#{payload.queue}", id)
|
76
|
+
payload
|
71
77
|
else
|
72
78
|
false
|
73
79
|
end
|
74
80
|
end
|
75
81
|
|
76
82
|
def register_worker(worker)
|
83
|
+
logger.debug "Registering worker #{worker.id}"
|
77
84
|
redis.set("worker:#{worker.id}", encode(worker.attributes))
|
78
85
|
redis.sadd(:workers, worker.id)
|
79
86
|
end
|
80
87
|
|
81
|
-
def unregister_worker(
|
82
|
-
|
83
|
-
redis.
|
88
|
+
def unregister_worker(worker)
|
89
|
+
logger.debug "Unregistering worker #{worker.id}"
|
90
|
+
redis.del("worker:#{worker.id}")
|
91
|
+
redis.srem('workers', worker.id)
|
84
92
|
end
|
85
93
|
|
86
94
|
def workers
|
@@ -88,7 +96,9 @@ module Qu
|
|
88
96
|
end
|
89
97
|
|
90
98
|
def clear_workers
|
99
|
+
logger.info "Clearing workers"
|
91
100
|
while id = redis.spop(:workers)
|
101
|
+
logger.debug "Clearing worker #{id}"
|
92
102
|
redis.del("worker:#{id}")
|
93
103
|
end
|
94
104
|
end
|
@@ -102,7 +112,7 @@ module Qu
|
|
102
112
|
def get(id)
|
103
113
|
if data = redis.get("job:#{id}")
|
104
114
|
data = decode(data)
|
105
|
-
|
115
|
+
Payload.new(:id => id, :klass => data['klass'], :args => data['args'])
|
106
116
|
end
|
107
117
|
end
|
108
118
|
|
metadata
CHANGED
@@ -1,112 +1,80 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: qu-redis
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 0
|
10
|
-
version: 0.1.0
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Brandon Keepers
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2011-10-03 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
22
15
|
name: redis-namespace
|
23
|
-
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &70323678030260 !ruby/object:Gem::Requirement
|
25
17
|
none: false
|
26
|
-
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
segments:
|
31
|
-
- 0
|
32
|
-
version: "0"
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
33
22
|
type: :runtime
|
34
|
-
version_requirements: *id001
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
name: simple_uuid
|
37
23
|
prerelease: false
|
38
|
-
|
24
|
+
version_requirements: *70323678030260
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: simple_uuid
|
27
|
+
requirement: &70323678029840 !ruby/object:Gem::Requirement
|
39
28
|
none: false
|
40
|
-
requirements:
|
41
|
-
- -
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
|
44
|
-
segments:
|
45
|
-
- 0
|
46
|
-
version: "0"
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
47
33
|
type: :runtime
|
48
|
-
version_requirements: *id002
|
49
|
-
- !ruby/object:Gem::Dependency
|
50
|
-
name: qu
|
51
34
|
prerelease: false
|
52
|
-
|
35
|
+
version_requirements: *70323678029840
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: qu
|
38
|
+
requirement: &70323678029360 !ruby/object:Gem::Requirement
|
53
39
|
none: false
|
54
|
-
requirements:
|
55
|
-
- -
|
56
|
-
- !ruby/object:Gem::Version
|
57
|
-
|
58
|
-
segments:
|
59
|
-
- 0
|
60
|
-
- 1
|
61
|
-
- 0
|
62
|
-
version: 0.1.0
|
40
|
+
requirements:
|
41
|
+
- - =
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.1.1
|
63
44
|
type: :runtime
|
64
|
-
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70323678029360
|
65
47
|
description: Redis backend for qu
|
66
|
-
email:
|
48
|
+
email:
|
67
49
|
- brandon@opensoul.org
|
68
50
|
executables: []
|
69
|
-
|
70
51
|
extensions: []
|
71
|
-
|
72
52
|
extra_rdoc_files: []
|
73
|
-
|
74
|
-
files:
|
53
|
+
files:
|
75
54
|
- lib/qu-redis.rb
|
76
55
|
- lib/qu/backend/redis.rb
|
77
|
-
has_rdoc: true
|
78
56
|
homepage: http://github.com/bkeepers/qu
|
79
57
|
licenses: []
|
80
|
-
|
81
58
|
post_install_message:
|
82
59
|
rdoc_options: []
|
83
|
-
|
84
|
-
require_paths:
|
60
|
+
require_paths:
|
85
61
|
- lib
|
86
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
63
|
none: false
|
88
|
-
requirements:
|
89
|
-
- -
|
90
|
-
- !ruby/object:Gem::Version
|
91
|
-
|
92
|
-
|
93
|
-
- 0
|
94
|
-
version: "0"
|
95
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ! '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
69
|
none: false
|
97
|
-
requirements:
|
98
|
-
- -
|
99
|
-
- !ruby/object:Gem::Version
|
100
|
-
|
101
|
-
segments:
|
102
|
-
- 0
|
103
|
-
version: "0"
|
70
|
+
requirements:
|
71
|
+
- - ! '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
104
74
|
requirements: []
|
105
|
-
|
106
75
|
rubyforge_project:
|
107
|
-
rubygems_version: 1.6
|
76
|
+
rubygems_version: 1.8.6
|
108
77
|
signing_key:
|
109
78
|
specification_version: 3
|
110
79
|
summary: Redis backend for qu
|
111
80
|
test_files: []
|
112
|
-
|