girl_friday 0.9.7 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.md +6 -0
- data/LICENSE +20 -0
- data/README.md +1 -1
- data/girl_friday.gemspec +1 -1
- data/lib/girl_friday/version.rb +1 -1
- data/lib/girl_friday/work_queue.rb +25 -10
- data/test/test_girl_friday_queue.rb +46 -1
- metadata +11 -13
- data/TODO.md +0 -5
data/History.md
CHANGED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Mike Perham
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -77,7 +77,7 @@ From wikipedia:
|
|
77
77
|
Thanks
|
78
78
|
--------------------
|
79
79
|
|
80
|
-
[Carbon Five](http://carbonfive.com), I
|
80
|
+
[Carbon Five](http://carbonfive.com), I wrote and maintained girl\_friday on their clock.
|
81
81
|
|
82
82
|
This gem contains a copy of the Rubinius Actor API, modified to work on any Ruby VM. Thanks to Evan Phoenix, MenTaLguY and the Rubinius project for permission to use and distribute this code.
|
83
83
|
|
data/girl_friday.gemspec
CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
17
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
18
|
s.require_paths = ["lib"]
|
19
|
-
s.add_dependency 'connection_pool', '~> 0.
|
19
|
+
s.add_dependency 'connection_pool', '~> 0.9.0'
|
20
20
|
s.add_development_dependency 'sinatra', '~> 1.3'
|
21
21
|
s.add_development_dependency 'rake'
|
22
22
|
end
|
data/lib/girl_friday/version.rb
CHANGED
@@ -14,6 +14,7 @@ module GirlFriday
|
|
14
14
|
@error_handlers = (Array(options[:error_handler] || ErrorHandler.default)).map(&:new)
|
15
15
|
|
16
16
|
@shutdown = false
|
17
|
+
@shutting_down = false
|
17
18
|
@busy_workers = []
|
18
19
|
@ready_workers = nil
|
19
20
|
@created_at = Time.now.to_i
|
@@ -76,6 +77,10 @@ module GirlFriday
|
|
76
77
|
@supervisor << Shutdown[block]
|
77
78
|
end
|
78
79
|
|
80
|
+
def working?
|
81
|
+
@busy_workers.size > 0
|
82
|
+
end
|
83
|
+
|
79
84
|
private
|
80
85
|
|
81
86
|
def running?
|
@@ -89,7 +94,7 @@ module GirlFriday
|
|
89
94
|
|
90
95
|
def on_ready(who)
|
91
96
|
@total_processed += 1
|
92
|
-
if running? && work = @persister.pop
|
97
|
+
if !shutting_down? && running? && work = @persister.pop
|
93
98
|
who.this << work
|
94
99
|
drain
|
95
100
|
else
|
@@ -108,10 +113,13 @@ module GirlFriday
|
|
108
113
|
end
|
109
114
|
end
|
110
115
|
|
116
|
+
def shutting_down?
|
117
|
+
!!@shutting_down
|
118
|
+
end
|
119
|
+
|
111
120
|
def on_work(work)
|
112
121
|
@total_queued += 1
|
113
|
-
|
114
|
-
if running? && worker = ready_workers.pop
|
122
|
+
if !shutting_down? && running? && worker = ready_workers.pop
|
115
123
|
@busy_workers << worker
|
116
124
|
worker << work
|
117
125
|
drain
|
@@ -174,13 +182,19 @@ module GirlFriday
|
|
174
182
|
on_work(work)
|
175
183
|
end
|
176
184
|
f.when(Shutdown) do |stop|
|
177
|
-
@
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
185
|
+
@shutting_down = true
|
186
|
+
if !working?
|
187
|
+
@shutdown = true
|
188
|
+
@when_shutdown = stop.callback
|
189
|
+
@busy_workers.each { |w| w << stop }
|
190
|
+
ready_workers.each { |w| w << stop }
|
191
|
+
shutdown_complete
|
192
|
+
GirlFriday.remove_queue @weakref
|
193
|
+
return
|
194
|
+
else
|
195
|
+
Thread.pass
|
196
|
+
shutdown(&stop.callback)
|
197
|
+
end
|
184
198
|
end
|
185
199
|
f.when(Actor::DeadActorError) do |ex|
|
186
200
|
if running?
|
@@ -189,6 +203,7 @@ module GirlFriday
|
|
189
203
|
@busy_workers.delete(ex.actor)
|
190
204
|
ready_workers << Actor.spawn_link(&@work_loop)
|
191
205
|
handle_error(ex.reason)
|
206
|
+
drain
|
192
207
|
end
|
193
208
|
end
|
194
209
|
end
|
@@ -36,6 +36,25 @@ class TestGirlFridayQueue < MiniTest::Unit::TestCase
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
+
def test_should_handle_worker_error_with_retry
|
40
|
+
async_test do |cb|
|
41
|
+
TestErrorHandler.send(:define_method, :handle) do |ex|
|
42
|
+
end
|
43
|
+
|
44
|
+
queue = GirlFriday::WorkQueue.new('error', :error_handler => TestErrorHandler, :size => 1) do |msg|
|
45
|
+
begin
|
46
|
+
raise 'oops' if msg == 1
|
47
|
+
queue.shutdown do
|
48
|
+
cb.call
|
49
|
+
end
|
50
|
+
ensure
|
51
|
+
queue.push(0)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
queue.push(1)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
39
58
|
def test_should_use_a_default_error_handler_when_none_specified
|
40
59
|
async_test do |cb|
|
41
60
|
queue = GirlFriday::WorkQueue.new('error') do |msg|
|
@@ -106,7 +125,7 @@ class TestGirlFridayQueue < MiniTest::Unit::TestCase
|
|
106
125
|
require 'redis'
|
107
126
|
require 'connection_pool'
|
108
127
|
pool = ConnectionPool.new(:size => 5, :timeout => 2){ Redis.new }
|
109
|
-
pool.flushdb
|
128
|
+
pool.with_connection {|redis| redis.flushdb }
|
110
129
|
rescue LoadError
|
111
130
|
return puts "Skipping redis test, 'redis' gem not found: #{$!.message}"
|
112
131
|
rescue Errno::ECONNREFUSED
|
@@ -170,6 +189,32 @@ class TestGirlFridayQueue < MiniTest::Unit::TestCase
|
|
170
189
|
end
|
171
190
|
end
|
172
191
|
|
192
|
+
def test_should_allow_in_progress_work_to_finish
|
193
|
+
mutex = Mutex.new
|
194
|
+
total = 8
|
195
|
+
count = 0
|
196
|
+
incr = Proc.new do
|
197
|
+
mutex.synchronize do
|
198
|
+
count += 1
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
async_test(10) do |cb|
|
203
|
+
queue = GirlFriday::WorkQueue.new('finish', :size => 10) do |msg|
|
204
|
+
sleep 1
|
205
|
+
incr.call
|
206
|
+
end
|
207
|
+
total.times do
|
208
|
+
queue.push(:text => 'foo')
|
209
|
+
end
|
210
|
+
|
211
|
+
GirlFriday.shutdown!
|
212
|
+
assert_equal total, queue.instance_variable_get("@total_processed")
|
213
|
+
assert_equal total, count
|
214
|
+
cb.call
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
173
218
|
def test_should_create_workers_lazily
|
174
219
|
async_test do |cb|
|
175
220
|
queue = GirlFriday::Queue.new('lazy', :size => 2) do |msg|
|
metadata
CHANGED
@@ -2,47 +2,46 @@
|
|
2
2
|
name: girl_friday
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.10.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Mike Perham
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
default_executable:
|
12
|
+
date: 2012-08-02 00:00:00.000000000Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: connection_pool
|
17
|
-
version_requirements: &
|
16
|
+
version_requirements: &2056 !ruby/object:Gem::Requirement
|
18
17
|
requirements:
|
19
18
|
- - ~>
|
20
19
|
- !ruby/object:Gem::Version
|
21
|
-
version: 0.
|
20
|
+
version: 0.9.0
|
22
21
|
none: false
|
23
|
-
requirement: *
|
22
|
+
requirement: *2056
|
24
23
|
prerelease: false
|
25
24
|
type: :runtime
|
26
25
|
- !ruby/object:Gem::Dependency
|
27
26
|
name: sinatra
|
28
|
-
version_requirements: &
|
27
|
+
version_requirements: &2074 !ruby/object:Gem::Requirement
|
29
28
|
requirements:
|
30
29
|
- - ~>
|
31
30
|
- !ruby/object:Gem::Version
|
32
31
|
version: '1.3'
|
33
32
|
none: false
|
34
|
-
requirement: *
|
33
|
+
requirement: *2074
|
35
34
|
prerelease: false
|
36
35
|
type: :development
|
37
36
|
- !ruby/object:Gem::Dependency
|
38
37
|
name: rake
|
39
|
-
version_requirements: &
|
38
|
+
version_requirements: &2092 !ruby/object:Gem::Requirement
|
40
39
|
requirements:
|
41
40
|
- - ! '>='
|
42
41
|
- !ruby/object:Gem::Version
|
43
42
|
version: '0'
|
44
43
|
none: false
|
45
|
-
requirement: *
|
44
|
+
requirement: *2092
|
46
45
|
prerelease: false
|
47
46
|
type: :development
|
48
47
|
description: Background processing, simplified
|
@@ -57,9 +56,9 @@ files:
|
|
57
56
|
- .travis.yml
|
58
57
|
- Gemfile
|
59
58
|
- History.md
|
59
|
+
- LICENSE
|
60
60
|
- README.md
|
61
61
|
- Rakefile
|
62
|
-
- TODO.md
|
63
62
|
- config.ru
|
64
63
|
- examples/backends/mongo_persistence.rb
|
65
64
|
- examples/backends/using_mongo.rb
|
@@ -84,7 +83,6 @@ files:
|
|
84
83
|
- test/test_girl_friday.rb
|
85
84
|
- test/test_girl_friday_immediately.rb
|
86
85
|
- test/test_girl_friday_queue.rb
|
87
|
-
has_rdoc: true
|
88
86
|
homepage: http://github.com/mperham/girl_friday
|
89
87
|
licenses: []
|
90
88
|
post_install_message:
|
@@ -105,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
103
|
none: false
|
106
104
|
requirements: []
|
107
105
|
rubyforge_project: girl_friday
|
108
|
-
rubygems_version: 1.
|
106
|
+
rubygems_version: 1.8.15
|
109
107
|
signing_key:
|
110
108
|
specification_version: 3
|
111
109
|
summary: Background processing, simplified
|