queue_ding 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.semver +2 -2
- data/Gemfile.lock +8 -8
- data/README.rdoc +25 -1
- data/lib/queue_ding/queue_ding.rb +26 -6
- data/queue_ding.gemspec +3 -3
- data/spec/queue_ding_spec.rb +17 -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: 0f1c6406efd9e78c4821822dc95d0375f197ab13
|
4
|
+
data.tar.gz: 28ef2796ec8115cc2e78e926828e39298ab53d1d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9e7bb7e88433ee1240d6c559b8bb0adeb82ef9bac21f26afd81d88342e20a8836ff7078c8cd14b6da8229b79bb2be7fbbec30db5dc1784a6853949dcd3e25af
|
7
|
+
data.tar.gz: c8e7717f0b41820038ffca2c25af3467cd7eddeab2b8ff350c3442e35b4e67707e4fe3670c705e94efe97e4508a6251725e0f4bbbf5049ecf3c34d4db4f00c3d
|
data/.semver
CHANGED
data/Gemfile.lock
CHANGED
@@ -15,14 +15,14 @@ GEM
|
|
15
15
|
multipart-post (>= 1.2, < 3)
|
16
16
|
ffi (1.9.3)
|
17
17
|
formatador (0.2.5)
|
18
|
-
git (1.2.
|
19
|
-
github_api (0.
|
18
|
+
git (1.2.8)
|
19
|
+
github_api (0.12.0)
|
20
20
|
addressable (~> 2.3)
|
21
|
-
descendants_tracker (~> 0.0.
|
21
|
+
descendants_tracker (~> 0.0.4)
|
22
22
|
faraday (~> 0.8, < 0.10)
|
23
|
-
hashie (>=
|
23
|
+
hashie (>= 3.2)
|
24
24
|
multi_json (>= 1.7.5, < 2.0)
|
25
|
-
nokogiri (~> 1.6.
|
25
|
+
nokogiri (~> 1.6.3)
|
26
26
|
oauth2
|
27
27
|
guard (2.6.1)
|
28
28
|
formatador (>= 0.2.4)
|
@@ -55,7 +55,7 @@ GEM
|
|
55
55
|
multi_json (1.10.1)
|
56
56
|
multi_xml (0.5.5)
|
57
57
|
multipart-post (2.0.0)
|
58
|
-
nokogiri (1.6.
|
58
|
+
nokogiri (1.6.3.1)
|
59
59
|
mini_portile (= 0.6.0)
|
60
60
|
oauth2 (1.0.0)
|
61
61
|
faraday (>= 0.8, < 0.10)
|
@@ -79,9 +79,9 @@ GEM
|
|
79
79
|
rspec-expectations (~> 2.99.0)
|
80
80
|
rspec-mocks (~> 2.99.0)
|
81
81
|
rspec-core (2.99.1)
|
82
|
-
rspec-expectations (2.99.
|
82
|
+
rspec-expectations (2.99.2)
|
83
83
|
diff-lcs (>= 1.1.3, < 2.0)
|
84
|
-
rspec-mocks (2.99.
|
84
|
+
rspec-mocks (2.99.2)
|
85
85
|
semver (1.0.1)
|
86
86
|
simplecov (0.9.0)
|
87
87
|
docile (~> 1.1.0)
|
data/README.rdoc
CHANGED
@@ -8,6 +8,24 @@ Because this is derived directly from the Array class, it has all the
|
|
8
8
|
expected Array functionality, with the appropriate wrappers for thread
|
9
9
|
safety.
|
10
10
|
|
11
|
+
== New Funtionality
|
12
|
+
=== v0.1.0
|
13
|
+
Automatic tee support added, so that multiple listening threads will
|
14
|
+
get the same data. There is currenly no way to turn this feature
|
15
|
+
off. If this is a problem for you, let me know and I'll add a switch
|
16
|
+
sooner.
|
17
|
+
|
18
|
+
You may not want this behavior if you are using queue_ding to distrubute
|
19
|
+
work among listening threads, but you will want this if you need to ensure
|
20
|
+
multile listeners receive the smae data, as in the case with with my
|
21
|
+
dyamic interfaces for browser-based Dashboards.
|
22
|
+
|
23
|
+
== Known Issues
|
24
|
+
=== v0.1.0
|
25
|
+
With the new Automatic Tee Feature, there is currently no cleanup
|
26
|
+
for dead threads. This could potentially lead to a memory leak situation
|
27
|
+
for long running tasks. This problem will be addressed in the next release.
|
28
|
+
|
11
29
|
== Gem Version
|
12
30
|
{<img src="https://badge.fury.io/rb/queue_ding.png" alt="Gem Version" />}[http://badge.fury.io/rb/queue_ding]
|
13
31
|
|
@@ -38,7 +56,13 @@ This is taken from the rspec tests.
|
|
38
56
|
tout.join
|
39
57
|
|
40
58
|
|
41
|
-
==
|
59
|
+
== Changelog
|
60
|
+
|
61
|
+
v0.1.0 2014-08-03
|
62
|
+
Added tee capability so that you can tee queue to multiple threads
|
63
|
+
automatically. There are no settings for this. It just works. For some,
|
64
|
+
this behavior may be undesirable, so an option will be added at a later
|
65
|
+
date.
|
42
66
|
|
43
67
|
== Copyright
|
44
68
|
|
@@ -12,6 +12,7 @@ be relaxed.
|
|
12
12
|
|
13
13
|
require 'aquarium'
|
14
14
|
require 'thread'
|
15
|
+
require 'set'
|
15
16
|
|
16
17
|
module QueueDing
|
17
18
|
|
@@ -22,10 +23,13 @@ module QueueDing
|
|
22
23
|
class QDing < Array
|
23
24
|
include Aquarium::DSL
|
24
25
|
|
25
|
-
|
26
|
+
# These accessors are ONLY used internally, and are
|
27
|
+
# subject to change.
|
28
|
+
attr_accessor :semaphore, :resource, :listener_threads
|
26
29
|
|
27
30
|
def initialize
|
28
31
|
super
|
32
|
+
@listener_threads = Set.new
|
29
33
|
@semaphore = Mutex.new
|
30
34
|
@resource = ConditionVariable.new
|
31
35
|
end
|
@@ -34,6 +38,7 @@ module QueueDing
|
|
34
38
|
alias_method :dequeue, :shift
|
35
39
|
alias_method :enqueue, :push
|
36
40
|
alias_method :enqueue, :push
|
41
|
+
|
37
42
|
# enqueue, and others that need protection for multithreading
|
38
43
|
around calls_to: [:<<,
|
39
44
|
:enqueue,
|
@@ -54,15 +59,30 @@ module QueueDing
|
|
54
59
|
] do |join_point, q, *args|
|
55
60
|
result = nil
|
56
61
|
q.semaphore.synchronize {
|
57
|
-
|
62
|
+
q.listener_threads << (curth = Thread.current)
|
63
|
+
curth[:localq] ||= []
|
64
|
+
|
65
|
+
while q.empty? and curth[:localq].empty?
|
58
66
|
q.resource.wait(q.semaphore)
|
59
67
|
end
|
60
|
-
|
68
|
+
# At this point, at least one of the queues have something.
|
69
|
+
# What we do here is that if we have something in the main
|
70
|
+
# queue? We distribute that to the other waiting threads.
|
71
|
+
# Those threads will check their own localq to see if they have
|
72
|
+
# an entry, etc.
|
73
|
+
result = unless curth[:localq].empty?
|
74
|
+
curth[:localq].shift
|
75
|
+
else
|
76
|
+
r = join_point.proceed
|
77
|
+
q.listener_threads.reject{|t|
|
78
|
+
t == curth
|
79
|
+
}.each{ |t|
|
80
|
+
t[:localq] << r
|
81
|
+
}
|
82
|
+
r
|
83
|
+
end
|
61
84
|
}
|
62
85
|
result
|
63
86
|
end
|
64
87
|
end
|
65
|
-
|
66
88
|
end
|
67
|
-
|
68
|
-
|
data/queue_ding.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: queue_ding 0.0
|
5
|
+
# stub: queue_ding 0.1.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "queue_ding"
|
9
|
-
s.version = "0.0
|
9
|
+
s.version = "0.1.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Fred Mitchell"]
|
14
|
-
s.date = "2014-
|
14
|
+
s.date = "2014-08-03"
|
15
15
|
s.description = "\n This roughly mirrors the functionaly of Queue in allowing you to\n queue messages to one or more threads, and will block if the queue\n is empty, waking up when there is another message available.\n "
|
16
16
|
s.email = "lordalveric@yahoo.com"
|
17
17
|
s.extra_rdoc_files = [
|
data/spec/queue_ding_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
require 'thread'
|
3
3
|
|
4
|
-
CNT =
|
4
|
+
CNT = 10000
|
5
5
|
CNTI = CNT
|
6
6
|
CNTO = CNT
|
7
7
|
|
@@ -48,4 +48,20 @@ describe QueueDing::QDing do
|
|
48
48
|
tout.join
|
49
49
|
expect(@queue.empty?).to be_truthy
|
50
50
|
end
|
51
|
+
|
52
|
+
it "handles teeing" do
|
53
|
+
tg = ThreadGroup.new
|
54
|
+
tg.add Thread.new {
|
55
|
+
sleep 5
|
56
|
+
(0..CNT).each{|i| @queue << i }
|
57
|
+
}
|
58
|
+
|
59
|
+
20.times do
|
60
|
+
tg.add Thread.new {
|
61
|
+
(0..CNT).each{|i| expect(i).to eq @queue.next }
|
62
|
+
}
|
63
|
+
end
|
64
|
+
|
65
|
+
tg.list.each {|t| t.join }
|
66
|
+
end
|
51
67
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: queue_ding
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fred Mitchell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aquarium
|