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 CHANGED
@@ -1,5 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
+ - 2.0.0
4
5
  - jruby-19mode
5
6
 
data/README.md CHANGED
@@ -49,7 +49,7 @@ class MetricWorker < Sideband::Worker
49
49
  end
50
50
 
51
51
  def call
52
- Work.create!(@params)
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
@@ -6,7 +6,7 @@ module Sideband
6
6
  def initialize(manager)
7
7
  @manager = manager
8
8
  @thread = ::Thread.new do
9
- while work = @manager.queue.pop
9
+ while @manager.queue && work = @manager.queue.pop
10
10
  exit if work.nil?
11
11
 
12
12
  begin
@@ -1,3 +1,3 @@
1
1
  module Sideband
2
- VERSION = '1.0.1'
2
+ VERSION = '1.0.2'
3
3
  end
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
- manager.queue
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
- raise NotInitializedError.new('Sideband must be initialized! before using.') if manager.nil?
49
+ manager = initialize! if manager.nil?
45
50
  manager
46
51
  end
47
52
 
data/sideband.gemspec CHANGED
@@ -18,4 +18,5 @@ Gem::Specification.new do |gem|
18
18
  gem.require_paths = ['lib']
19
19
 
20
20
  gem.add_development_dependency 'rake'
21
+ gem.add_development_dependency 'minitest', '~> 4.6.2'
21
22
  end
data/test/helper.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'minitest/autorun'
2
+ require 'minitest/mock'
2
3
  require 'sideband'
3
4
 
4
5
  class EmailWorker < Sideband::Worker
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.1
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.1
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
@@ -2,10 +2,8 @@ require 'helper'
2
2
 
3
3
  class TestSideband < MiniTest::Unit::TestCase
4
4
 
5
- def test_must_be_initialized_before_use
6
- assert_raises Sideband::NotInitializedError do
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.1
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-03-16 00:00:00.000000000 Z
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: !ruby/object:Gem::Requirement
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: '0'
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.25
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: