background_worker 0.2.0 → 0.2.1
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.
- checksums.yaml +4 -4
- data/.travis.yml +7 -0
- data/CHANGELOG.md +4 -0
- data/Rakefile +12 -1
- data/background_worker.gemspec +3 -0
- data/gemfiles/rails3.gemfile +6 -0
- data/gemfiles/rails4_0.gemfile +6 -0
- data/gemfiles/rails4_1.gemfile +6 -0
- data/gemfiles/rails4_2.gemfile +6 -0
- data/gemfiles/rails5_0.gemfile +6 -0
- data/gemfiles/rails5_1.gemfile +6 -0
- data/lib/background_worker/base.rb +3 -5
- data/lib/background_worker/config.rb +2 -1
- data/lib/background_worker/version.rb +1 -1
- data/spec/base_spec.rb +39 -0
- data/spec/schema.rb +5 -0
- data/spec/support/coverage_loader.rb +1 -1
- metadata +40 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: adc5011226295995d19e4fac5920ec5507921e1b
|
4
|
+
data.tar.gz: 358a861e8f41d6a66ffdebf64d561521cf766608
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 56cc930cc991e58352cda3fe9cf687d92dc7d5e1dcc3d8e5c6af088d6aab4b27d36bba7cca9efb7615a501cbf408a6db117ebc49de3d93ea7b2f2c0ffee89c4d
|
7
|
+
data.tar.gz: 8bf4c992d2233f2224c6a2a7595014f628ab9bea24c392bcb6d4207bfd801140ed42c9dd4947fa69c2196647e51d41448cfd6987b44f8081557bf27cd95f55a2
|
data/.travis.yml
CHANGED
@@ -3,6 +3,13 @@ rvm:
|
|
3
3
|
- 2.2.2
|
4
4
|
- 2.3.0
|
5
5
|
script: bundle exec rake spec
|
6
|
+
gemfile:
|
7
|
+
- gemfiles/rails3.gemfile
|
8
|
+
- gemfiles/rails4_0.gemfile
|
9
|
+
- gemfiles/rails4_1.gemfile
|
10
|
+
- gemfiles/rails4_2.gemfile
|
11
|
+
- gemfiles/rails5_0.gemfile
|
12
|
+
- gemfiles/rails5_1.gemfile
|
6
13
|
notifications:
|
7
14
|
email:
|
8
15
|
- support@travellink.com.au
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,10 @@ This changelog adheres to [Keep a CHANGELOG](http://keepachangelog.com/).
|
|
5
5
|
|
6
6
|
## Unreleased
|
7
7
|
|
8
|
+
## 0.2.1
|
9
|
+
### Fixed
|
10
|
+
- [RU-123] Worker disconnecting within transactions in rails 4+
|
11
|
+
|
8
12
|
## 0.2.0
|
9
13
|
### Added
|
10
14
|
- [RU-79] Release connections after execution for Rails 4
|
data/Rakefile
CHANGED
@@ -1 +1,12 @@
|
|
1
|
-
require
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
3
|
+
desc 'Default: run specs.'
|
4
|
+
task :default => :spec
|
5
|
+
|
6
|
+
require 'rspec/core/rake_task'
|
7
|
+
|
8
|
+
desc "Run specs"
|
9
|
+
RSpec::Core::RakeTask.new do |t|
|
10
|
+
t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
|
11
|
+
# Put spec opts in a file named .rspec in root
|
12
|
+
end
|
data/background_worker.gemspec
CHANGED
@@ -28,4 +28,7 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.add_development_dependency 'coveralls'
|
29
29
|
spec.add_development_dependency 'simplecov-rcov'
|
30
30
|
spec.add_development_dependency 'rubocop'
|
31
|
+
|
32
|
+
spec.add_development_dependency 'activerecord'
|
33
|
+
spec.add_development_dependency 'sqlite3'
|
31
34
|
end
|
@@ -7,14 +7,12 @@ module BackgroundWorker
|
|
7
7
|
attr_accessor :uid, :state
|
8
8
|
|
9
9
|
def initialize(options = {})
|
10
|
-
Time.zone = Setting.time_zone
|
11
|
-
|
12
10
|
@uid = options[:uid]
|
13
11
|
|
14
12
|
# Store state persistently, to enable status checkups & progress reporting
|
15
13
|
@state = BackgroundWorker::PersistentState.new(@uid, options.except(:uid))
|
16
14
|
log("Created #{self.class}")
|
17
|
-
log("Options are: #{options.
|
15
|
+
log("Options are: #{options.inspect}")
|
18
16
|
end
|
19
17
|
|
20
18
|
# Report progress...
|
@@ -79,13 +77,13 @@ module BackgroundWorker
|
|
79
77
|
#
|
80
78
|
# It will just call your preferred method in the worker.
|
81
79
|
def perform(method_name, options = {})
|
82
|
-
BackgroundWorker.verify_active_connections!
|
80
|
+
BackgroundWorker.verify_active_connections! if BackgroundWorker.config.backgrounded
|
83
81
|
|
84
82
|
worker = new(options)
|
85
83
|
execution = WorkerExecution.new(worker, method_name, options)
|
86
84
|
execution.call
|
87
85
|
ensure
|
88
|
-
BackgroundWorker.release_connections!
|
86
|
+
BackgroundWorker.release_connections! if BackgroundWorker.config.backgrounded
|
89
87
|
end
|
90
88
|
end
|
91
89
|
end
|
@@ -2,7 +2,7 @@ require 'logger'
|
|
2
2
|
|
3
3
|
module BackgroundWorker
|
4
4
|
class Config
|
5
|
-
attr_reader :logger, :enqueue_with
|
5
|
+
attr_reader :logger, :enqueue_with, :backgrounded
|
6
6
|
|
7
7
|
# Configuration includes following options:
|
8
8
|
# logger: what logger to user throughout
|
@@ -19,6 +19,7 @@ module BackgroundWorker
|
|
19
19
|
@logger = attrs.fetch(:logger, ::Logger.new(STDOUT))
|
20
20
|
@enqueue_with = attrs.fetch(:enqueue_with, method(:foreground_enqueue))
|
21
21
|
@after_exception = attrs.fetch(:after_exception, method(:default_after_exception))
|
22
|
+
@backgrounded = attrs.fetch(:backgrounded, true)
|
22
23
|
end
|
23
24
|
|
24
25
|
# Callback fired when an exception occurs
|
data/spec/base_spec.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'active_support/core_ext/hash/keys' # Hash.symbolize_keys
|
4
|
+
require 'active_support/core_ext/numeric/time' # Numeric.hours
|
5
|
+
|
6
|
+
require 'active_record'
|
7
|
+
|
8
|
+
DB_FILE = 'tmp/test_db'
|
9
|
+
FileUtils.mkdir_p File.dirname(DB_FILE)
|
10
|
+
FileUtils.rm_f DB_FILE
|
11
|
+
|
12
|
+
ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => DB_FILE
|
13
|
+
|
14
|
+
load('spec/schema.rb')
|
15
|
+
|
16
|
+
describe BackgroundWorker::Base do
|
17
|
+
let(:cache) { double(write: nil, read: nil, reconnect: nil, store: nil) }
|
18
|
+
let(:model_class) { Model = Class.new(ActiveRecord::Base) }
|
19
|
+
let(:worker_class) {
|
20
|
+
Class.new(BackgroundWorker::Base) do
|
21
|
+
def store_in_cache(opts)
|
22
|
+
Rails.cache.store(opts[:value])
|
23
|
+
end
|
24
|
+
end
|
25
|
+
}
|
26
|
+
|
27
|
+
before do
|
28
|
+
stub_const 'Model', model_class
|
29
|
+
stub_const 'Rails', double(cache: cache, env: 'production')
|
30
|
+
BackgroundWorker.configure(backgrounded: false)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should perform action and handle transactions/connections appropriately' do
|
34
|
+
Model.transaction do
|
35
|
+
worker_class.perform_in_background(:store_in_cache, value: 42)
|
36
|
+
end
|
37
|
+
expect(cache).to have_received(:store).with(42)
|
38
|
+
end
|
39
|
+
end
|
data/spec/schema.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: background_worker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Noack
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2017-
|
13
|
+
date: 2017-09-14 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
@@ -124,6 +124,34 @@ dependencies:
|
|
124
124
|
- - ">="
|
125
125
|
- !ruby/object:Gem::Version
|
126
126
|
version: '0'
|
127
|
+
- !ruby/object:Gem::Dependency
|
128
|
+
name: activerecord
|
129
|
+
requirement: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
type: :development
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
|
+
- !ruby/object:Gem::Dependency
|
142
|
+
name: sqlite3
|
143
|
+
requirement: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ">="
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
type: :development
|
149
|
+
prerelease: false
|
150
|
+
version_requirements: !ruby/object:Gem::Requirement
|
151
|
+
requirements:
|
152
|
+
- - ">="
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: '0'
|
127
155
|
description: See README for full details
|
128
156
|
email:
|
129
157
|
- development@travellink.com.au
|
@@ -142,6 +170,12 @@ files:
|
|
142
170
|
- README.md
|
143
171
|
- Rakefile
|
144
172
|
- background_worker.gemspec
|
173
|
+
- gemfiles/rails3.gemfile
|
174
|
+
- gemfiles/rails4_0.gemfile
|
175
|
+
- gemfiles/rails4_1.gemfile
|
176
|
+
- gemfiles/rails4_2.gemfile
|
177
|
+
- gemfiles/rails5_0.gemfile
|
178
|
+
- gemfiles/rails5_1.gemfile
|
145
179
|
- lib/background_worker.rb
|
146
180
|
- lib/background_worker/base.rb
|
147
181
|
- lib/background_worker/config.rb
|
@@ -149,6 +183,8 @@ files:
|
|
149
183
|
- lib/background_worker/uid.rb
|
150
184
|
- lib/background_worker/version.rb
|
151
185
|
- lib/background_worker/worker_execution.rb
|
186
|
+
- spec/base_spec.rb
|
187
|
+
- spec/schema.rb
|
152
188
|
- spec/spec_helper.rb
|
153
189
|
- spec/support/coverage_loader.rb
|
154
190
|
- spec/uid_spec.rb
|
@@ -177,6 +213,8 @@ signing_key:
|
|
177
213
|
specification_version: 4
|
178
214
|
summary: Background worker abstraction with status updates
|
179
215
|
test_files:
|
216
|
+
- spec/base_spec.rb
|
217
|
+
- spec/schema.rb
|
180
218
|
- spec/spec_helper.rb
|
181
219
|
- spec/support/coverage_loader.rb
|
182
220
|
- spec/uid_spec.rb
|