daemonic 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/daemonic/pool.rb +26 -13
- data/lib/daemonic/producer.rb +7 -7
- data/lib/daemonic/version.rb +1 -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: 02568ce6526b1a6407039c4abb9b45d005bf5e7f
|
4
|
+
data.tar.gz: 388216ee58cdbc4b272f15b76df288ebe65d29c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4d4bd93c7b5f861f7bc1fb575bb613ee9756a5a285f618821ce4b649592cdf3fd83fec2be636213088eeb19944cfde31c0d3dc738b6dd2665bb0a2b37dec110
|
7
|
+
data.tar.gz: 80879158acec4db8a26fdc654ff8329f410ff92c6b93f0c31a2ed99e09991afdce1ec12d2492c98e8653e915ba2b0a38f955b63bf96f5e716bed449ab641c80d
|
data/lib/daemonic/pool.rb
CHANGED
@@ -13,11 +13,12 @@ module Daemonic
|
|
13
13
|
|
14
14
|
STOP_SIGNAL = StopSignal.new
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
@
|
20
|
-
@
|
16
|
+
attr_reader :producer
|
17
|
+
|
18
|
+
def initialize(producer)
|
19
|
+
@producer = producer
|
20
|
+
@jobs = SizedQueue.new(producer.queue_size)
|
21
|
+
@threads = producer.concurrency.times.map {|worker_num|
|
21
22
|
Thread.new do
|
22
23
|
dispatch(worker_num)
|
23
24
|
end
|
@@ -25,7 +26,7 @@ module Daemonic
|
|
25
26
|
end
|
26
27
|
|
27
28
|
def enqueue(job)
|
28
|
-
|
29
|
+
logger.debug { "Enqueueing #{job.inspect}" }
|
29
30
|
@jobs.push(job)
|
30
31
|
end
|
31
32
|
alias_method :<<, :enqueue
|
@@ -40,26 +41,38 @@ module Daemonic
|
|
40
41
|
private
|
41
42
|
|
42
43
|
def dispatch(worker_num)
|
43
|
-
|
44
|
+
logger.debug { "T#{worker_num}: Starting" }
|
44
45
|
loop do
|
45
46
|
job = @jobs.pop
|
46
47
|
if STOP_SIGNAL.equal?(job)
|
47
|
-
|
48
|
+
logger.debug { "T#{worker_num}: Received stop signal, terminating." }
|
48
49
|
break
|
49
50
|
end
|
50
51
|
begin
|
51
|
-
|
52
|
-
|
52
|
+
logger.debug { "T#{worker_num}: Consuming #{job.inspect}" }
|
53
|
+
worker.consume(job)
|
53
54
|
Thread.pass
|
54
55
|
rescue Object => error
|
55
|
-
|
56
|
-
|
56
|
+
if error.is_a?(SystemExit) # allow app to exit
|
57
|
+
logger.warn { "T#{worker_num}: Received SystemExit, shutting down" }
|
58
|
+
producer.stop
|
59
|
+
else
|
60
|
+
logger.warn { "T#{worker_num}: #{error.class} while processing #{job}: #{error}" }
|
61
|
+
logger.info { error.backtrace.join("\n") }
|
62
|
+
end
|
57
63
|
Thread.pass
|
58
64
|
end
|
59
65
|
end
|
60
|
-
|
66
|
+
logger.debug { "T#{worker_num}: Stopped" }
|
67
|
+
end
|
68
|
+
|
69
|
+
def worker
|
70
|
+
producer.worker
|
61
71
|
end
|
62
72
|
|
73
|
+
def logger
|
74
|
+
producer.logger
|
75
|
+
end
|
63
76
|
|
64
77
|
end
|
65
78
|
end
|
data/lib/daemonic/producer.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
module Daemonic
|
2
2
|
class Producer
|
3
3
|
|
4
|
-
attr_reader :worker, :
|
4
|
+
attr_reader :worker, :concurrency, :options, :queue_size
|
5
5
|
|
6
6
|
def initialize(worker, options)
|
7
|
-
@worker
|
8
|
-
@options
|
7
|
+
@worker = worker
|
8
|
+
@options = options
|
9
9
|
@concurrency = options.fetch(:concurrency) { 4 }
|
10
|
-
|
11
|
-
@
|
12
|
-
@running
|
10
|
+
@queue_size = options.fetch(:queue_size) { @concurrency + 1 }
|
11
|
+
@logger = options[:logger]
|
12
|
+
@running = true
|
13
13
|
end
|
14
14
|
|
15
15
|
def run
|
@@ -18,7 +18,7 @@ module Daemonic
|
|
18
18
|
Signal.trap("INT") { stop }
|
19
19
|
Signal.trap("TERM") { stop }
|
20
20
|
|
21
|
-
pool = Pool.new(
|
21
|
+
pool = Pool.new(self)
|
22
22
|
|
23
23
|
producer = Thread.new do
|
24
24
|
while @running
|
data/lib/daemonic/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: daemonic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- iain
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|