sideband 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +5 -0
- data/README.md +58 -2
- data/lib/sideband/version.rb +1 -1
- data/sideband.gemspec +2 -0
- data/test/helper.rb +4 -0
- data/test/test_manager.rb +12 -9
- metadata +29 -7
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
# Sideband
|
2
2
|
|
3
|
-
|
3
|
+
Run simple jobs in a separate sideband thread.
|
4
|
+
|
5
|
+
Sideband makes it easy to pass small jobs off to a separate in-process thread. It makes no attempt to handle errors, nor return any results. Its primary focus is queueing up potentially IO blocking bits of code, where the results of which are not necessarily vital to your application's business logic.
|
6
|
+
|
7
|
+
Use cases:
|
8
|
+
*
|
9
|
+
|
4
10
|
|
5
11
|
## Installation
|
6
12
|
|
@@ -18,7 +24,57 @@ Or install it yourself as:
|
|
18
24
|
|
19
25
|
## Usage
|
20
26
|
|
21
|
-
|
27
|
+
To be used Sideband needs to be intialized, typically in an Rails initializer (but can be used outside of Rails).
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
Sideband.initialize!
|
31
|
+
```
|
32
|
+
|
33
|
+
In theory you can create one Sideband thread per thread, however it's most useful in your main thread.
|
34
|
+
|
35
|
+
To pass work off to Sideband, you can add anything that is callable (procs, lambdas, workers) to its queue:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
Sideband.queue << -> { Something.expensive }
|
39
|
+
```
|
40
|
+
|
41
|
+
Sideband will queue the work, then return immediately. The work will get called whenever the thread scheduler schedules the worker thread--typically after your controller renders.
|
42
|
+
|
43
|
+
Sideband is truly fire-and-forget, any exceptions are caught and thrown away. If you want to handle exception, you should probably do so in a custom worker.
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
class MetricWorker < Sideband::Worker
|
47
|
+
def initialize(params)
|
48
|
+
@params = params
|
49
|
+
end
|
50
|
+
|
51
|
+
def call
|
52
|
+
Work.create!(@params)
|
53
|
+
rescue ActiveRecord::RecordInvalid
|
54
|
+
Rails.logger.error("Could not save Metric: #{@params}")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
Sideband.queue << MetricWorker.new(params[:metric])
|
59
|
+
|
60
|
+
# or Sideband::Workers can enqueue themselves
|
61
|
+
|
62
|
+
Metricworker.new(params[:metric]).enqueue
|
63
|
+
```
|
64
|
+
|
65
|
+
## Use Cases
|
66
|
+
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
@user = User.create(params[:user])
|
70
|
+
Sideband.queue << -> { UserMailer.welcome_email(@user).deliver }
|
71
|
+
render :welcome
|
72
|
+
```
|
73
|
+
|
74
|
+
## Code Status
|
75
|
+
|
76
|
+
[![Build Status](https://api.travis-ci.org/mje113/sideband.png)](http://travis-ci.org/mje113/sideband)
|
77
|
+
[![Code Climate](https://codeclimate.com/github/mje113/sideband.png)](https://codeclimate.com/github/mje113/sideband)
|
22
78
|
|
23
79
|
## Contributing
|
24
80
|
|
data/lib/sideband/version.rb
CHANGED
data/sideband.gemspec
CHANGED
data/test/helper.rb
CHANGED
data/test/test_manager.rb
CHANGED
@@ -29,16 +29,19 @@ class TestManager < MiniTest::Unit::TestCase
|
|
29
29
|
assert_equal 'finished', worker.work
|
30
30
|
end
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
32
|
+
if !jruby?
|
33
|
+
def test_fork_handling
|
34
|
+
puts RUBY_PLATFORM
|
35
|
+
queue = @manager.queue
|
36
|
+
thread = @manager.thread
|
37
|
+
|
38
|
+
Process.stub(:pid, Process.pid + 1) do
|
39
|
+
@manager.queue << -> { 'work' }
|
40
|
+
refute_equal queue, @manager.queue
|
41
|
+
refute_equal thread, @manager.thread
|
42
|
+
end
|
41
43
|
end
|
44
|
+
end
|
42
45
|
|
43
46
|
def test_killed
|
44
47
|
@manager.kill
|
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.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,24 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
13
|
-
dependencies:
|
12
|
+
date: 2013-03-16 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
14
30
|
description: Run simple workers in a separate thread
|
15
31
|
email:
|
16
32
|
- mike@urlgonomics.com
|
@@ -19,6 +35,7 @@ extensions: []
|
|
19
35
|
extra_rdoc_files: []
|
20
36
|
files:
|
21
37
|
- .gitignore
|
38
|
+
- .travis.yml
|
22
39
|
- Gemfile
|
23
40
|
- LICENSE.txt
|
24
41
|
- README.md
|
@@ -45,18 +62,24 @@ require_paths:
|
|
45
62
|
required_ruby_version: !ruby/object:Gem::Requirement
|
46
63
|
none: false
|
47
64
|
requirements:
|
48
|
-
- -
|
65
|
+
- - '>='
|
49
66
|
- !ruby/object:Gem::Version
|
50
67
|
version: '0'
|
68
|
+
segments:
|
69
|
+
- 0
|
70
|
+
hash: -823111614033344564
|
51
71
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
72
|
none: false
|
53
73
|
requirements:
|
54
|
-
- -
|
74
|
+
- - '>='
|
55
75
|
- !ruby/object:Gem::Version
|
56
76
|
version: '0'
|
77
|
+
segments:
|
78
|
+
- 0
|
79
|
+
hash: -823111614033344564
|
57
80
|
requirements: []
|
58
81
|
rubyforge_project:
|
59
|
-
rubygems_version: 1.8.
|
82
|
+
rubygems_version: 1.8.25
|
60
83
|
signing_key:
|
61
84
|
specification_version: 3
|
62
85
|
summary: Run simple workers in a separate thread
|
@@ -67,4 +90,3 @@ test_files:
|
|
67
90
|
- test/test_sideband.rb
|
68
91
|
- test/test_thread.rb
|
69
92
|
- test/test_worker.rb
|
70
|
-
has_rdoc:
|