threaded_in_memory_queue 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +20 -4
- data/lib/threaded_in_memory_queue.rb +25 -14
- data/lib/threaded_in_memory_queue/version.rb +1 -1
- data/test/threaded_in_memory_queue/config_test.rb +45 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7fd506634cc145e6c56e1e10deb6c71b6df2721a
|
4
|
+
data.tar.gz: b3cd8cc4435837aaf9f3032e1b63e5852bb679a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53b102591e99d460779bf499cdb29422fa69eb4448119797a3cd62d50496bfa565c84a5ded0fde3e12115bdcde9286052e5f776925dc088cbc39038cbdc2b785
|
7
|
+
data.tar.gz: f48dfc1c7284f51da6051cb8271beb273e80ceb1f1eee79547016aba2005faf293eb80ac0922512d4499e52a496b16c940ae5baac886b89dc61b55e1ef97d610
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -54,19 +54,31 @@ The first argument is a class that defines the task to be processed and the rest
|
|
54
54
|
The default number of worker threads is 16, you can configure that when you start your queue:
|
55
55
|
|
56
56
|
```ruby
|
57
|
-
ThreadedInMemoryQueue.
|
57
|
+
ThreadedInMemoryQueue.config do |config|
|
58
|
+
config.size = 5
|
59
|
+
end
|
58
60
|
```
|
59
61
|
|
60
62
|
By default jobs have a timeout value of 60 seconds. Since this is an in-memory queue (goes away when your process terminates) it is in your best interests to keep jobs small and quick, and not overload the queue. You can configure a different timeout on start:
|
61
63
|
|
62
64
|
```ruby
|
63
|
-
ThreadedInMemoryQueue.
|
65
|
+
ThreadedInMemoryQueue.config do |config|
|
66
|
+
config.timeout = 90 # timeout is in seconds
|
67
|
+
end
|
64
68
|
```
|
65
69
|
|
66
70
|
Want a different logger? Specify a different Logger:
|
67
71
|
|
68
72
|
```ruby
|
69
|
-
ThreadedInMemoryQueue.
|
73
|
+
ThreadedInMemoryQueue.config do |config|
|
74
|
+
config.logger = Logger.new(STDOUT)
|
75
|
+
end
|
76
|
+
```
|
77
|
+
|
78
|
+
Make sure to configure before you start your queue. You can also inline your config if you want when you start the queue:
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
ThreadedInMemoryQueue.start(size: 5, timeout: 90, logger: Logger.new(STDOUT))
|
70
82
|
```
|
71
83
|
|
72
84
|
For testing or guaranteed code execution use the Inline option:
|
@@ -89,7 +101,11 @@ at_exit do
|
|
89
101
|
end
|
90
102
|
```
|
91
103
|
|
92
|
-
This call takes an optional timeout value (in seconds)
|
104
|
+
This call takes an optional timeout value (in seconds).
|
105
|
+
|
106
|
+
```ruby
|
107
|
+
ThreadedInMemoryQueue.stop(42)
|
108
|
+
```
|
93
109
|
|
94
110
|
## License
|
95
111
|
|
@@ -6,35 +6,46 @@ require 'threaded_in_memory_queue/version'
|
|
6
6
|
require 'threaded_in_memory_queue/timeout'
|
7
7
|
|
8
8
|
module ThreadedInMemoryQueue
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
STOP_TIMEOUT = 10 # seconds
|
10
|
+
extend self
|
11
|
+
attr_accessor :inline, :logger, :size, :timeout
|
12
|
+
alias :inline? :inline
|
13
13
|
|
14
|
-
def
|
15
|
-
self.logger
|
16
|
-
self.
|
14
|
+
def start(options = {})
|
15
|
+
self.logger = options[:logger] if options[:logger]
|
16
|
+
self.size = options[:size] if options[:size]
|
17
|
+
self.timeout = options[:timeout] if options[:timeout]
|
18
|
+
self.master = Master.new(logger: self.logger,
|
19
|
+
size: self.size,
|
20
|
+
timeout: self.timeout)
|
21
|
+
self.master.start
|
17
22
|
return self
|
18
23
|
end
|
19
24
|
|
20
|
-
def
|
25
|
+
def configure(&block)
|
26
|
+
raise "Queue is already started, must configure queue before starting" if started?
|
27
|
+
yield self
|
28
|
+
end
|
29
|
+
alias :config :configure
|
30
|
+
|
31
|
+
def started?
|
21
32
|
return false unless master
|
22
33
|
master.alive?
|
23
34
|
end
|
24
35
|
|
25
|
-
def
|
36
|
+
def stopped?
|
26
37
|
!started?
|
27
38
|
end
|
28
39
|
|
29
|
-
def
|
40
|
+
def master
|
30
41
|
@master
|
31
42
|
end
|
32
43
|
|
33
|
-
def
|
44
|
+
def master=(master)
|
34
45
|
@master = master
|
35
46
|
end
|
36
47
|
|
37
|
-
def
|
48
|
+
def enqueue(job, *args)
|
38
49
|
if inline?
|
39
50
|
job.call(*args)
|
40
51
|
else
|
@@ -44,14 +55,14 @@ module ThreadedInMemoryQueue
|
|
44
55
|
return true
|
45
56
|
end
|
46
57
|
|
47
|
-
def
|
58
|
+
def stop(timeout = STOP_TIMEOUT)
|
48
59
|
return true unless master
|
49
60
|
master.stop(timeout)
|
50
61
|
return true
|
51
62
|
end
|
52
63
|
end
|
53
64
|
|
54
|
-
ThreadedInMemoryQueue.logger
|
65
|
+
ThreadedInMemoryQueue.logger = Logger.new(STDOUT)
|
55
66
|
ThreadedInMemoryQueue.logger.level = Logger::INFO
|
56
67
|
|
57
68
|
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'stringio'
|
3
|
+
|
4
|
+
class ConfigTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def teardown
|
7
|
+
ThreadedInMemoryQueue.stop
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_config_works
|
11
|
+
fake_out = StringIO.new
|
12
|
+
logger = Logger.new(fake_out)
|
13
|
+
size = rand(1..99)
|
14
|
+
timeout = rand(1..99)
|
15
|
+
|
16
|
+
ThreadedInMemoryQueue.configure do |config|
|
17
|
+
config.size = size
|
18
|
+
config.logger = logger
|
19
|
+
config.timeout = timeout
|
20
|
+
end
|
21
|
+
|
22
|
+
ThreadedInMemoryQueue.start
|
23
|
+
|
24
|
+
assert_equal ThreadedInMemoryQueue.size, size
|
25
|
+
assert_equal ThreadedInMemoryQueue.master.instance_variable_get("@size"), size
|
26
|
+
|
27
|
+
assert_equal ThreadedInMemoryQueue.timeout, timeout
|
28
|
+
assert_equal ThreadedInMemoryQueue.master.instance_variable_get("@timeout"), timeout
|
29
|
+
|
30
|
+
assert_equal ThreadedInMemoryQueue.logger, logger
|
31
|
+
assert_equal ThreadedInMemoryQueue.master.instance_variable_get("@logger"), logger
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_config_cannot_call_after_start
|
35
|
+
ThreadedInMemoryQueue.start
|
36
|
+
assert_raise(RuntimeError) do
|
37
|
+
ThreadedInMemoryQueue.configure do |config|
|
38
|
+
config.size = size
|
39
|
+
config.logger = logger
|
40
|
+
config.timeout = timeout
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: threaded_in_memory_queue
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Schneeman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-10-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -58,6 +58,7 @@ files:
|
|
58
58
|
- lib/threaded_in_memory_queue/version.rb
|
59
59
|
- lib/threaded_in_memory_queue/worker.rb
|
60
60
|
- test/test_helper.rb
|
61
|
+
- test/threaded_in_memory_queue/config_test.rb
|
61
62
|
- test/threaded_in_memory_queue/master_test.rb
|
62
63
|
- test/threaded_in_memory_queue/worker_test.rb
|
63
64
|
- test/threaded_in_memory_queue_test.rb
|
@@ -88,6 +89,7 @@ specification_version: 4
|
|
88
89
|
summary: Memory, Enqueue stuff you will
|
89
90
|
test_files:
|
90
91
|
- test/test_helper.rb
|
92
|
+
- test/threaded_in_memory_queue/config_test.rb
|
91
93
|
- test/threaded_in_memory_queue/master_test.rb
|
92
94
|
- test/threaded_in_memory_queue/worker_test.rb
|
93
95
|
- test/threaded_in_memory_queue_test.rb
|