spawnling 2.1.4 → 2.1.5

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: 26aa7286ca5e508bb9bec2971336151f68d64225
4
- data.tar.gz: e70bf1b0865d216b5d3a197268eff1af8021e70f
3
+ metadata.gz: 46683af41ff0f9b4d4078d02a1009371670f1c0e
4
+ data.tar.gz: 114aa427aabb0bfc096967528b53fb1ca6a2aed8
5
5
  SHA512:
6
- metadata.gz: 01315192fee03920aba467775e9f59801340dce832a3ba6c32b2a3643b7b0f730a8ac58a92b674b11a22ea09ee748688539d43f008cb9da0f6c55bd1a9a15814
7
- data.tar.gz: e03db92b7c3c476190a89b032160928541c31f15d9068578b19c421bf8669e50d99c40ced3cbe97621270fc4165d021929af381002a878ab739f6122c55747c6
6
+ metadata.gz: fefb1f49fa3a27b0b3fd8d5d645738fe27623881e01e804946e4c9645231443067fea45df43e26be5f5f92b4626165dbf81f22e510f3809a1b22b9946a72745a
7
+ data.tar.gz: 8601bbf865be9fac8277b402d25418e4125305d0bd01b573f86a0a67bbabd2f429f9bb08bd2e8c49eb6fbd714c00339a209e84ba76a911717398050d0b1e9f4a
data/.gitignore CHANGED
@@ -1,2 +1,4 @@
1
1
  *~
2
2
  *.gem
3
+ .project
4
+ foo
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format documentation
3
+ --backtrace
data/.travis.yml CHANGED
@@ -5,15 +5,14 @@ rvm:
5
5
  - 2.0
6
6
  - 2.1
7
7
  gemfile:
8
- - gemfiles/rails2.gemfile
9
8
  - gemfiles/rails3.gemfile
10
9
  - gemfiles/rails4.gemfile
10
+ env:
11
+ - NONE=true
12
+ - RAILS=true
13
+ - RAILS=true MEMCACHE=true
11
14
  matrix:
12
15
  exclude:
13
- - rvm: 2.0
14
- gemfile: gemfiles/rails2.gemfile
15
- - rvm: 2.1
16
- gemfile: gemfiles/rails2.gemfile
17
16
  - rvm: 1.8.7
18
17
  gemfile: gemfiles/rails4.gemfile
19
18
  script: "bundle exec rake coverage"
data/lib/patches.rb CHANGED
@@ -2,7 +2,11 @@ if defined?(ActiveRecord)
2
2
  # see activerecord/lib/active_record/connection_adaptors/abstract/connection_specification.rb
3
3
  class ActiveRecord::Base
4
4
  # reconnect without disconnecting
5
- if ::Spawnling::RAILS_3_x || ::Spawnling::RAILS_2_2
5
+ if ::Spawnling::RAILS_3_x
6
+ def self.spawn_reconnect(klass=self)
7
+ ActiveRecord::Base.connection.reconnect!
8
+ end
9
+ elsif ::Spawnling::RAILS_2_2
6
10
  def self.spawn_reconnect(klass=self)
7
11
  # keep ancestors' connection_handlers around to avoid them being garbage collected in the forked child
8
12
  @@ancestor_connection_handlers ||= []
@@ -130,6 +134,8 @@ if need_passenger_patch
130
134
  end
131
135
  end
132
136
 
133
- if defined?(::ActiveSupport::Cache::MemCacheStore)
134
- ::ActiveSupport::Cache::MemCacheStore.delegate :reset, :to => :@data
137
+ if defined?(Rails)
138
+ if defined?(::ActiveSupport::Cache::MemCacheStore) && Rails.cache.class.name == 'ActiveSupport::Cache::MemCacheStore'
139
+ ::ActiveSupport::Cache::MemCacheStore.delegate :reset, :to => :@data
140
+ end
135
141
  end
data/lib/spawnling.rb CHANGED
@@ -95,7 +95,7 @@ class Spawnling
95
95
  # :method => :thread or override the default behavior in the environment by setting
96
96
  # 'Spawnling::method :thread'.
97
97
  def initialize(opts = {}, &block)
98
- self.class.run(opts, &block)
98
+ @type, @handle = self.class.run(opts, &block)
99
99
  end
100
100
 
101
101
  def self.run(opts = {}, &block)
@@ -109,15 +109,13 @@ class Spawnling
109
109
  elsif options[:method] == :thread
110
110
  # for versions before 2.2, check for allow_concurrency
111
111
  if allow_concurrency?
112
- @type = :thread
113
- @handle = thread_it(options) { yield }
112
+ return :thread, thread_it(options) { yield }
114
113
  else
115
114
  @@logger.error("spawn(:method=>:thread) only allowed when allow_concurrency=true")
116
115
  raise "spawn requires config.active_record.allow_concurrency=true when used with :method=>:thread"
117
116
  end
118
117
  else
119
- @type = :fork
120
- @handle = fork_it(options) { yield }
118
+ return :fork, fork_it(options) { yield }
121
119
  end
122
120
  end
123
121
 
@@ -125,7 +123,7 @@ class Spawnling
125
123
  return true if RAILS_2_2
126
124
  if defined?(ActiveRecord) && ActiveRecord::Base.respond_to?(:allow_concurrency)
127
125
  ActiveRecord::Base.allow_concurrency
128
- elsif defined?(Rails)
126
+ elsif defined?(Rails) && Rails.application
129
127
  Rails.application.config.allow_concurrency
130
128
  else
131
129
  true # assume user knows what they are doing
@@ -146,7 +144,7 @@ class Spawnling
146
144
  end
147
145
  end
148
146
  # clean up connections from expired threads
149
- ActiveRecord::Base.verify_active_connections!() if defined?(ActiveRecord)
147
+ clean_connections
150
148
  end
151
149
 
152
150
  protected
@@ -218,11 +216,11 @@ class Spawnling
218
216
 
219
217
  def self.thread_it(options)
220
218
  # clean up stale connections from previous threads
221
- ActiveRecord::Base.verify_active_connections!() if defined?(ActiveRecord)
219
+ clean_connections
222
220
  thr = Thread.new do
223
221
  # run the long-running code block
224
222
  if defined?(ActiveRecord)
225
- ActiveRecord::Base.connection_pool.with_connection { yield }
223
+ ActiveRecord::Base.connection_pool.with_connection { yield }
226
224
  else
227
225
  yield
228
226
  end
@@ -231,6 +229,12 @@ class Spawnling
231
229
  return thr
232
230
  end
233
231
 
232
+ def self.clean_connections
233
+ return unless defined? ActiveRecord
234
+ ActiveRecord::Base.verify_active_connections! if ActiveRecord::Base.respond_to?(:verify_active_connections!)
235
+ ActiveRecord::Base.clear_active_connections! if ActiveRecord::Base.respond_to?(:clear_active_connections!)
236
+ end
237
+
234
238
  # In case we don't have rails, can't call opts.symbolize_keys
235
239
  def self.symbolize_options(hash)
236
240
  hash.inject({}) do |new_hash, (key, value)|
@@ -1,3 +1,3 @@
1
1
  class Spawnling
2
- VERSION = '2.1.4'
2
+ VERSION = '2.1.5'
3
3
  end
data/spawnling.gemspec CHANGED
@@ -7,8 +7,8 @@ Gem::Specification.new do |s|
7
7
  s.name = "spawnling"
8
8
  s.version = Spawnling::VERSION
9
9
 
10
- s.authors = ['Tom Anderson']
11
- s.email = ['tom@squeat.com']
10
+ s.authors = ['Tom Anderson', 'Michael Noack']
11
+ s.email = ['tom@squeat.com', 'michael+spawnling@noack.com.au']
12
12
 
13
13
  s.homepage = %q{http://github.com/tra/spawnling}
14
14
  s.license = "MIT"
@@ -29,6 +29,10 @@ threads (see lib/patches.rb).}
29
29
  s.add_development_dependency 'bundler'
30
30
  s.add_development_dependency 'rake'
31
31
  s.add_development_dependency 'rspec', '~> 2.0'
32
+ s.add_development_dependency 'simplecov'
33
+ s.add_development_dependency 'simplecov-rcov'
32
34
  s.add_development_dependency 'coveralls'
33
35
  s.add_development_dependency 'rails'
36
+ s.add_development_dependency 'activerecord-nulldb-adapter'
37
+ s.add_development_dependency 'dalli'
34
38
  end
@@ -14,32 +14,32 @@ describe Spawnling do
14
14
  object.do_something
15
15
  end
16
16
  end
17
-
17
+
18
18
  it "should be able to yield directly" do
19
19
  spawn!.should == "hello"
20
20
  end
21
21
  end
22
-
22
+
23
23
  describe "override" do
24
24
  before(:each) do
25
25
  Spawnling::default_options :method => proc{ "foo" }
26
26
  end
27
-
27
+
28
28
  it "should be able to return a proc" do
29
29
  spawn!.should == "foo"
30
30
  end
31
-
31
+
32
32
  end
33
-
33
+
34
34
  describe "delegate to a proc" do
35
35
  before(:each) do
36
36
  Spawnling::default_options :method => proc{ |block| block }
37
37
  end
38
-
38
+
39
39
  it "should be able to return a proc" do
40
40
  spawn!.should be_kind_of(Proc)
41
41
  end
42
-
42
+
43
43
  it "should be able to return a proc" do
44
44
  spawn!.call.should == "hello"
45
45
  end
@@ -57,8 +57,18 @@ describe Spawnling do
57
57
  sleep(0.1) # wait for file to finish writing
58
58
  Store.flag.should be_truthy
59
59
  end
60
+
61
+ it "instance should have a type" do
62
+ instance = Spawnling.new{}
63
+ instance.type.should be(:thread)
64
+ end
65
+
66
+ it "instance should have a handle" do
67
+ instance = Spawnling.new{}
68
+ instance.handle.should_not be_nil
69
+ end
60
70
  end
61
-
71
+
62
72
  describe "fork it" do
63
73
  before(:each) do
64
74
  Store.reset!
@@ -71,6 +81,16 @@ describe Spawnling do
71
81
  sleep(0.1) # wait for file to finish writing
72
82
  Store.flag.should be_truthy
73
83
  end
84
+
85
+ it "instance should have a type" do
86
+ instance = Spawnling.new{}
87
+ instance.type.should be(:fork)
88
+ end
89
+
90
+ it "instance should have a handle" do
91
+ instance = Spawnling.new{}
92
+ instance.handle.should_not be_nil
93
+ end
74
94
  end
75
95
 
76
96
  def spawn!
@@ -84,5 +104,5 @@ describe Spawnling do
84
104
  Store.flag!
85
105
  end
86
106
  end
87
-
107
+
88
108
  end
data/spec/spec_helper.rb CHANGED
@@ -5,18 +5,41 @@ require 'rspec'
5
5
  $:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
6
6
 
7
7
  require 'store'
8
+ if ENV['RAILS']
9
+ require 'rails'
10
+ require 'active_record'
11
+ end
12
+ ActiveRecord::Base.establish_connection :adapter => :nulldb if defined?(ActiveRecord)
13
+
14
+ MINIMUM_COVERAGE = 53
15
+
16
+ if ENV['RAILS']
17
+ class Application < Rails::Application
18
+ config.log_level = :warn
19
+ config.logger = Logger.new(STDOUT)
20
+ end
21
+ Application.initialize!
22
+ Application.config.allow_concurrency = true
23
+ end
8
24
 
9
- MINIMUM_COVERAGE = 40
25
+ if ENV['MEMCACHE']
26
+ Application.config.cache_store = :mem_cache_store
27
+ end
10
28
 
11
29
  if ENV['COVERAGE']
12
30
  require 'simplecov'
31
+ require 'simplecov-rcov'
13
32
  require 'coveralls'
14
33
  Coveralls.wear!
15
34
 
16
- SimpleCov.formatter = Coveralls::SimpleCov::Formatter
35
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
36
+ SimpleCov::Formatter::RcovFormatter,
37
+ Coveralls::SimpleCov::Formatter
38
+ ]
17
39
  SimpleCov.start do
18
40
  add_filter '/vendor/'
19
41
  add_filter '/spec/'
42
+ add_filter '/lib/patches.rb'
20
43
  add_group 'lib', 'lib'
21
44
  end
22
45
  SimpleCov.at_exit do
@@ -31,4 +54,3 @@ end
31
54
 
32
55
  require 'spawnling'
33
56
 
34
- Spawnling.logger = nil
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spawnling
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.4
4
+ version: 2.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Anderson
8
+ - Michael Noack
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2014-06-03 00:00:00.000000000 Z
12
+ date: 2014-07-06 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: bundler
@@ -52,6 +53,34 @@ dependencies:
52
53
  - - "~>"
53
54
  - !ruby/object:Gem::Version
54
55
  version: '2.0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: simplecov
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: simplecov-rcov
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
55
84
  - !ruby/object:Gem::Dependency
56
85
  name: coveralls
57
86
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +109,34 @@ dependencies:
80
109
  - - ">="
81
110
  - !ruby/object:Gem::Version
82
111
  version: '0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: activerecord-nulldb-adapter
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: dalli
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
83
140
  description: |-
84
141
  This plugin provides a 'Spawnling' class to easily fork OR
85
142
  thread long-running sections of code so that your application can return
@@ -90,11 +147,13 @@ description: |-
90
147
  threads (see lib/patches.rb).
91
148
  email:
92
149
  - tom@squeat.com
150
+ - michael+spawnling@noack.com.au
93
151
  executables: []
94
152
  extensions: []
95
153
  extra_rdoc_files: []
96
154
  files:
97
155
  - ".gitignore"
156
+ - ".rspec"
98
157
  - ".travis.yml"
99
158
  - CHANGELOG
100
159
  - Gemfile