nsque 0.0.4 → 0.0.5
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/lib/nsque.rb +0 -2
- data/lib/nsque/producer.rb +2 -3
- data/lib/nsque/testing_worker.rb +12 -8
- data/lib/nsque/version.rb +1 -1
- data/lib/nsque/worker.rb +21 -23
- data/nsque.gemspec +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 734f493bd1dd04ac57dbc697ee7480d40dab23f8
|
4
|
+
data.tar.gz: 77df636ef88b9d3f04cd9eac58a221325cb9c76e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 416fea2498eac34ea1ed5b3477ffec181c84ca8e6594be6db33b2feeeb47bcb0e4c783163d6e18e52f5b06216f0ca788666ffdf441826d3d6341c8d8e4315d3f
|
7
|
+
data.tar.gz: 72e29d7950c923480d5698b4a505c50f36bedc0fb7da31a1f28d82b1202af34fd1a1a4d09ea5598d3565dca9a3342968615f2f14de86de7aae808f5866268acb
|
data/lib/nsque.rb
CHANGED
data/lib/nsque/producer.rb
CHANGED
@@ -3,14 +3,13 @@ module Nsque
|
|
3
3
|
attr_reader :messages_count
|
4
4
|
|
5
5
|
def initialize(options = {})
|
6
|
-
|
7
|
-
@producer = Krakow::Producer.new(options)
|
6
|
+
@producer = Nsqrb::Producer.new(options[:host], options[:port], options[:topic])
|
8
7
|
@messages_count = 0
|
9
8
|
end
|
10
9
|
|
11
10
|
def write(item)
|
12
11
|
message = JSON.generate(item)
|
13
|
-
@producer.
|
12
|
+
@producer.post!(message)
|
14
13
|
@messages_count += 1
|
15
14
|
end
|
16
15
|
|
data/lib/nsque/testing_worker.rb
CHANGED
@@ -7,18 +7,22 @@ module Nsque
|
|
7
7
|
raise ProducerCantBeNilError.new if options[:producer].nil?
|
8
8
|
@options = options
|
9
9
|
@producer = options[:producer]
|
10
|
-
@consumer =
|
10
|
+
@consumer = Nsqrb::Consumer.new(@options)
|
11
|
+
@consumer.connect!
|
11
12
|
end
|
12
13
|
|
13
14
|
def process_all
|
14
15
|
count = 0
|
15
16
|
while @producer.messages_count > count
|
16
|
-
|
17
|
-
|
17
|
+
@consumer.receive
|
18
|
+
message = @consumer.messages.pop
|
19
|
+
next unless message
|
20
|
+
hash = JSON.parse(message.content)
|
18
21
|
begin
|
19
22
|
klass = hash['class'].constantize
|
20
23
|
klass.new.perform(hash['args'])
|
21
|
-
rescue
|
24
|
+
rescue => e
|
25
|
+
puts e.inspect
|
22
26
|
end
|
23
27
|
@consumer.confirm(message)
|
24
28
|
count += 1
|
@@ -30,11 +34,11 @@ module Nsque
|
|
30
34
|
|
31
35
|
def clear_all
|
32
36
|
count = 0
|
33
|
-
|
34
|
-
|
35
|
-
message = @consumer.
|
37
|
+
while @producer.messages_count > count
|
38
|
+
@consumer.receive
|
39
|
+
message = @consumer.messages.pop
|
40
|
+
next unless message
|
36
41
|
@consumer.confirm(message)
|
37
|
-
|
38
42
|
count += 1
|
39
43
|
end
|
40
44
|
|
data/lib/nsque/version.rb
CHANGED
data/lib/nsque/worker.rb
CHANGED
@@ -2,42 +2,40 @@ module Nsque
|
|
2
2
|
class Worker
|
3
3
|
|
4
4
|
def initialize(options)
|
5
|
-
Krakow::Utils::Logging.level = options.delete(:logging_level) || :warn
|
6
5
|
raise ChannelRequiredError.new unless options.has_key?(:channel)
|
7
6
|
@options = options
|
8
7
|
end
|
9
8
|
|
10
9
|
def run
|
11
|
-
consumer = Krakow::Consumer.new(@options)
|
12
10
|
initialize_traps
|
11
|
+
consumer = Nsqrb::Consumer.new(@options)
|
12
|
+
consumer.connect!
|
13
13
|
|
14
14
|
loop do
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
15
|
+
Timeout::timeout(1) { consumer.receive } rescue Timeout::Error
|
16
|
+
|
17
|
+
while message = consumer.messages.pop
|
18
|
+
begin
|
19
|
+
hash = JSON.parse(message.content)
|
20
|
+
puts hash.inspect
|
21
|
+
enqueue_after = (hash['at'].to_f - Time.now.to_f) * 1000
|
22
|
+
if enqueue_after <= 0
|
23
|
+
klass = hash['class'].constantize
|
24
|
+
klass.new.perform(hash['args'])
|
25
|
+
else
|
26
|
+
puts "Requeued: #{enqueue_after} ms"
|
27
|
+
consumer.requeue(message, enqueue_after.to_i)
|
28
|
+
next
|
29
|
+
end
|
30
|
+
rescue => e
|
31
|
+
p e.message
|
32
32
|
end
|
33
|
-
|
34
|
-
p e.message
|
33
|
+
consumer.confirm(message)
|
35
34
|
end
|
36
|
-
consumer.confirm(message)
|
37
35
|
break if @shutdown
|
38
36
|
end
|
39
37
|
ensure
|
40
|
-
consumer.
|
38
|
+
consumer.close! if consumer
|
41
39
|
end
|
42
40
|
|
43
41
|
private
|
data/nsque.gemspec
CHANGED
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nsque
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mikhail Salosin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: nsqrb
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.3
|
19
|
+
version: 0.0.3
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.3
|
26
|
+
version: 0.0.3
|
27
27
|
description: Background job library based on NSQ (http://nsq.io)
|
28
28
|
email: mikhail@salosin.me
|
29
29
|
executables: []
|