sideband 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +1 -0
- data/README.md +5 -1
- data/lib/sideband/thread.rb +1 -1
- data/lib/sideband/version.rb +1 -1
- data/lib/sideband.rb +11 -6
- data/sideband.gemspec +1 -0
- data/test/helper.rb +1 -0
- data/test/test_manager.rb +6 -5
- data/test/test_sideband.rb +9 -4
- metadata +17 -16
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -49,7 +49,7 @@ class MetricWorker < Sideband::Worker
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def call
|
52
|
-
|
52
|
+
Metric.create!(@params)
|
53
53
|
rescue ActiveRecord::RecordInvalid
|
54
54
|
Rails.logger.error("Could not save Metric: #{@params}")
|
55
55
|
end
|
@@ -76,6 +76,10 @@ render :welcome
|
|
76
76
|
[![Build Status](https://api.travis-ci.org/mje113/sideband.png)](http://travis-ci.org/mje113/sideband)
|
77
77
|
[![Code Climate](https://codeclimate.com/github/mje113/sideband.png)](https://codeclimate.com/github/mje113/sideband)
|
78
78
|
|
79
|
+
## Code Status
|
80
|
+
|
81
|
+
[![Code Climate](https://codeclimate.com/github/mje113/sideband.png)](https://codeclimate.com/github/mje113/sideband)
|
82
|
+
|
79
83
|
## Contributing
|
80
84
|
|
81
85
|
1. Fork it
|
data/lib/sideband/thread.rb
CHANGED
data/lib/sideband/version.rb
CHANGED
data/lib/sideband.rb
CHANGED
@@ -7,11 +7,8 @@ require 'sideband/worker'
|
|
7
7
|
|
8
8
|
module Sideband
|
9
9
|
|
10
|
-
class NotInitializedError < Exception; end
|
11
|
-
|
12
10
|
def self.initialize!
|
13
11
|
new_manager = Manager.new
|
14
|
-
puts 'Sideband initialized!'
|
15
12
|
|
16
13
|
if block_given?
|
17
14
|
begin
|
@@ -35,13 +32,21 @@ module Sideband
|
|
35
32
|
::Thread.current['sideband.manager'] = nil
|
36
33
|
end
|
37
34
|
|
38
|
-
def self.queue
|
39
|
-
|
35
|
+
def self.queue(job = nil)
|
36
|
+
if job
|
37
|
+
manager.queue << job
|
38
|
+
else
|
39
|
+
manager.queue
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.enqueue(job = nil)
|
44
|
+
queue(job)
|
40
45
|
end
|
41
46
|
|
42
47
|
def self.manager
|
43
48
|
manager = ::Thread.current['sideband.manager']
|
44
|
-
|
49
|
+
manager = initialize! if manager.nil?
|
45
50
|
manager
|
46
51
|
end
|
47
52
|
|
data/sideband.gemspec
CHANGED
data/test/helper.rb
CHANGED
data/test/test_manager.rb
CHANGED
@@ -15,33 +15,34 @@ class TestManager < MiniTest::Unit::TestCase
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def test_can_queue_and_process_proc
|
18
|
+
skip 'Testing thread scheduling is hard...'
|
18
19
|
work = 'work'
|
19
20
|
@manager.queue << -> { work = 'finished' }
|
20
|
-
sleep 0.
|
21
|
+
sleep 0.5
|
21
22
|
assert_equal 'finished', work
|
22
23
|
end
|
23
24
|
|
24
25
|
def test_can_queue_and_process_worker
|
26
|
+
skip 'Testing thread scheduling is hard...'
|
25
27
|
worker = EmailWorker.new
|
26
28
|
assert_equal 'work', worker.work
|
27
29
|
@manager.queue << worker
|
28
|
-
sleep 0.
|
30
|
+
sleep 0.5
|
29
31
|
assert_equal 'finished', worker.work
|
30
32
|
end
|
31
33
|
|
32
34
|
if !jruby?
|
33
35
|
def test_fork_handling
|
34
|
-
puts RUBY_PLATFORM
|
35
36
|
queue = @manager.queue
|
36
37
|
thread = @manager.thread
|
37
|
-
|
38
|
+
|
38
39
|
Process.stub(:pid, Process.pid + 1) do
|
39
40
|
@manager.queue << -> { 'work' }
|
40
41
|
refute_equal queue, @manager.queue
|
41
42
|
refute_equal thread, @manager.thread
|
42
43
|
end
|
44
|
+
end
|
43
45
|
end
|
44
|
-
end
|
45
46
|
|
46
47
|
def test_killed
|
47
48
|
@manager.kill
|
data/test/test_sideband.rb
CHANGED
@@ -2,10 +2,8 @@ require 'helper'
|
|
2
2
|
|
3
3
|
class TestSideband < MiniTest::Unit::TestCase
|
4
4
|
|
5
|
-
def
|
6
|
-
|
7
|
-
Sideband.queue << -> { 'work' }
|
8
|
-
end
|
5
|
+
def test_autoinitialization
|
6
|
+
assert Sideband.queue << -> { 'work' }
|
9
7
|
end
|
10
8
|
|
11
9
|
def test_has_queue
|
@@ -14,6 +12,13 @@ class TestSideband < MiniTest::Unit::TestCase
|
|
14
12
|
end
|
15
13
|
end
|
16
14
|
|
15
|
+
def test_can_access_queue_or_send_jobs
|
16
|
+
Sideband.initialize! do
|
17
|
+
assert Sideband.queue(-> { 'work' })
|
18
|
+
assert Sideband.enqueue(-> { 'work' })
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
17
22
|
def test_manager_stored_in_thread_current
|
18
23
|
Sideband.initialize! do
|
19
24
|
assert_kind_of Sideband::Manager, ::Thread.current['sideband.manager']
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sideband
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,24 +9,30 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-05-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirement: &70193563013700 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- - '>='
|
19
|
+
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: *70193563013700
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: minitest
|
27
|
+
requirement: &70193563013140 !ruby/object:Gem::Requirement
|
25
28
|
none: false
|
26
29
|
requirements:
|
27
|
-
- -
|
30
|
+
- - ~>
|
28
31
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
32
|
+
version: 4.6.2
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70193563013140
|
30
36
|
description: Run simple workers in a separate thread
|
31
37
|
email:
|
32
38
|
- mike@urlgonomics.com
|
@@ -62,24 +68,18 @@ require_paths:
|
|
62
68
|
required_ruby_version: !ruby/object:Gem::Requirement
|
63
69
|
none: false
|
64
70
|
requirements:
|
65
|
-
- - '>='
|
71
|
+
- - ! '>='
|
66
72
|
- !ruby/object:Gem::Version
|
67
73
|
version: '0'
|
68
|
-
segments:
|
69
|
-
- 0
|
70
|
-
hash: -823111614033344564
|
71
74
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
75
|
none: false
|
73
76
|
requirements:
|
74
|
-
- - '>='
|
77
|
+
- - ! '>='
|
75
78
|
- !ruby/object:Gem::Version
|
76
79
|
version: '0'
|
77
|
-
segments:
|
78
|
-
- 0
|
79
|
-
hash: -823111614033344564
|
80
80
|
requirements: []
|
81
81
|
rubyforge_project:
|
82
|
-
rubygems_version: 1.8.
|
82
|
+
rubygems_version: 1.8.17
|
83
83
|
signing_key:
|
84
84
|
specification_version: 3
|
85
85
|
summary: Run simple workers in a separate thread
|
@@ -90,3 +90,4 @@ test_files:
|
|
90
90
|
- test/test_sideband.rb
|
91
91
|
- test/test_thread.rb
|
92
92
|
- test/test_worker.rb
|
93
|
+
has_rdoc:
|