threaded_in_memory_queue 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 38361b605ed853eeb5af0accecf034f729c7b31b
4
- data.tar.gz: d34e9ac4ee7f2ae5facf364fbc0234d8f01e16e5
3
+ metadata.gz: 8caa931f0f7d256bef31f16943b720971a4aba33
4
+ data.tar.gz: 58779b11127871c2922e7d56ae1e65501e2e9264
5
5
  SHA512:
6
- metadata.gz: e5c37e3dd37bb4d273d2195792023148f81d278cb17b19f6d13a5f3c54ccb202a6ddcf6525c8807f5366170f76ad2a9dc91a722b12a33c04978e250e120a60a7
7
- data.tar.gz: 3ae6c5d6bd2f0ebc9a7301ed06defad3c63a537cef3ba6915449f103d48ed61c985c294df2bb6e77b43dd1b6dacffb9c5723bb03c8faec23879ae3ba2c45f17a
6
+ metadata.gz: 43b262f01b9b14826df1499106e037024d83d65098318831bd761ba32df9a91a2da57e001ea2390ddbb66682559ac2fb9b73c15119b65831cd11ede249124b07
7
+ data.tar.gz: 8754a70e9e7e994b89089cfeeeb2f84ba448e2f0d04953d473ab39a20652887846f5969280de16ca48cf677f33bab9e9034e6bf5eb73dafa93412b564ec9fab0
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- threaded_in_memory_queue (0.0.1)
4
+ threaded_in_memory_queue (0.0.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -3,14 +3,12 @@ require 'timeout'
3
3
  require 'logger'
4
4
 
5
5
  require 'threaded_in_memory_queue/version'
6
- require 'threaded_in_memory_queue/inline'
7
6
  require 'threaded_in_memory_queue/timeout'
8
7
 
9
8
  module ThreadedInMemoryQueue
10
- extend Inline
11
-
12
9
  class << self
13
- attr_accessor :logger
10
+ attr_accessor :logger, :inline
11
+ alias :inline? :inline
14
12
  end
15
13
 
16
14
  def self.start(options = {})
@@ -36,9 +34,13 @@ module ThreadedInMemoryQueue
36
34
  @master = master
37
35
  end
38
36
 
39
- def self.enqueue(klass, *args)
40
- raise NoWorkersError, "must start worker before enqueueing jobs" unless master
41
- master.enqueue(klass, *args)
37
+ def self.enqueue(job, *args)
38
+ if inline?
39
+ job.call(*args)
40
+ else
41
+ raise NoWorkersError unless started?
42
+ master.enqueue(job, *args)
43
+ end
42
44
  return true
43
45
  end
44
46
 
@@ -2,7 +2,6 @@ module ThreadedInMemoryQueue
2
2
  class Master
3
3
  include ThreadedInMemoryQueue::Timeout
4
4
  attr_reader :workers, :logger
5
- extend Inline
6
5
 
7
6
  DEFAULT_TIMEOUT = 60 # seconds, 1 minute
8
7
  DEFAULT_SIZE = 16
@@ -42,13 +41,9 @@ module ThreadedInMemoryQueue
42
41
  return self
43
42
  end
44
43
 
45
- def enqueue(klass, *json)
46
- if self.class.inline?
47
- klass.call(*json)
48
- else
49
- raise NoWorkersError, "No workers" unless alive?
50
- @queue.enq([klass, json])
51
- end
44
+ def enqueue(job, *json)
45
+ raise NoWorkersError unless alive?
46
+ @queue.enq([job, json])
52
47
  return true
53
48
  end
54
49
 
@@ -1,3 +1,3 @@
1
1
  module ThreadedInMemoryQueue
2
- VERSION = "0.0.2"
3
- end
2
+ VERSION = "0.0.3"
3
+ end
@@ -38,7 +38,7 @@ module ThreadedInMemoryQueue
38
38
  private
39
39
  def create_thread
40
40
  Thread.new {
41
- logger.info("Worker #{object_id} ready")
41
+ logger.info("Threaded In Memory Queue Worker '#{object_id}' ready")
42
42
  loop do
43
43
  payload = queue.pop
44
44
  job, json = *payload
@@ -48,7 +48,7 @@ module ThreadedInMemoryQueue
48
48
  job.call(*json)
49
49
  end
50
50
  end
51
- logger.info("Worker #{object_id} stopped")
51
+ logger.info("Threaded In Memory Queue Worker '#{object_id}' stopped")
52
52
  }
53
53
  end
54
54
  end
@@ -11,6 +11,18 @@ class ThreadedInMemoryQueueTest < Test::Unit::TestCase
11
11
  refute ThreadedInMemoryQueue.started?
12
12
  end
13
13
 
14
+ def test_inline
15
+ Dummy.expects(:process).with(1).once
16
+ job = Proc.new {|x| Dummy.process(x) }
17
+
18
+ ThreadedInMemoryQueue.inline = true
19
+ ThreadedInMemoryQueue.enqueue(job, 1)
20
+ assert ThreadedInMemoryQueue.inline
21
+ assert ThreadedInMemoryQueue.stopped?
22
+ ensure
23
+ ThreadedInMemoryQueue.inline = false
24
+ end
25
+
14
26
  def test_enqueues
15
27
  Dummy.expects(:process).with(1).once
16
28
  Dummy.expects(:process).with(2).once
@@ -21,7 +33,6 @@ class ThreadedInMemoryQueueTest < Test::Unit::TestCase
21
33
 
22
34
  ThreadedInMemoryQueue.enqueue(job, 1)
23
35
  ThreadedInMemoryQueue.enqueue(job, 2)
24
- ThreadedInMemoryQueue.stop
25
36
  ensure
26
37
  ThreadedInMemoryQueue.stop
27
38
  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.2
4
+ version: 0.0.3
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-09-06 00:00:00.000000000 Z
11
+ date: 2013-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -53,7 +53,6 @@ files:
53
53
  - Rakefile
54
54
  - lib/threaded_in_memory_queue.rb
55
55
  - lib/threaded_in_memory_queue/errors.rb
56
- - lib/threaded_in_memory_queue/inline.rb
57
56
  - lib/threaded_in_memory_queue/master.rb
58
57
  - lib/threaded_in_memory_queue/timeout.rb
59
58
  - lib/threaded_in_memory_queue/version.rb
@@ -1,15 +0,0 @@
1
- module ThreadedInMemoryQueue
2
- module Inline
3
- def inline
4
- @inline
5
- end
6
-
7
- def inline?
8
- inline
9
- end
10
-
11
- def inline=(inline)
12
- @inline = inline
13
- end
14
- end
15
- end