gb_dispatch 0.0.6 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 85cb910d1e03286d9c72c071f084ac3563cd7f0c
4
- data.tar.gz: 1a63ac0bedb03abd7581ff7f4e006d3dfa18271b
2
+ SHA256:
3
+ metadata.gz: 1600ca0fd7c8177491c2abdec098b6037dae32b2faf059250f4ed77c38febae5
4
+ data.tar.gz: 2743ee814e54779d75776d2c600bad4ae3c043d19603375dd0e98c0f69810e6d
5
5
  SHA512:
6
- metadata.gz: c6772bad44636c53a6e5416e5e36ac3abd70e8874c1515a5125d2248d116d4b7805f69c376b2d0ccd47144a71eddf2aef49a8bc7f0069a79c617ec3ac121b55e
7
- data.tar.gz: 47edbf55ad5183eae0d6c9a406c1376bbe6fd1f9db0bc503c6ec3ae554f5625b967fa7e58a09690324b1e53f540e751bc04af0e184bf74ec5029bb0a0ccdf64a
6
+ metadata.gz: 466fa59bc366831d2e0dcfb0402ab741fd3637af128527bbcdda7ada72f6fcecd414f8edd63d40cba451613ab25077da1e7524a1ec97fcea06d652cacc33eda1
7
+ data.tar.gz: 31b75abd8950d334db400cb0223e10f40fced8126fedd0989c975a11f5465227cd8192d18755cc0901fc6ba5d41a618d89e04a29b5658b5f36687e2d91c6e633
data/.idea/misc.xml CHANGED
@@ -1,14 +1,7 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <project version="4">
3
- <component name="ProjectLevelVcsManager" settingsEditedManually="false">
4
- <OptionsSetting value="true" id="Add" />
5
- <OptionsSetting value="true" id="Remove" />
6
- <OptionsSetting value="true" id="Checkout" />
7
- <OptionsSetting value="true" id="Update" />
8
- <OptionsSetting value="true" id="Status" />
9
- <OptionsSetting value="true" id="Edit" />
10
- <ConfirmationsSetting value="0" id="Add" />
11
- <ConfirmationsSetting value="0" id="Remove" />
3
+ <component name="JavaScriptSettings">
4
+ <option name="languageLevel" value="ES6" />
12
5
  </component>
13
- <component name="ProjectRootManager" version="2" project-jdk-name="RVM: ruby-1.9.3-p551 [global]" project-jdk-type="RUBY_SDK" />
6
+ <component name="ProjectRootManager" version="2" project-jdk-name="ruby-2.3.3-p222" project-jdk-type="RUBY_SDK" />
14
7
  </project>
data/.idea/modules.xml CHANGED
@@ -2,6 +2,7 @@
2
2
  <project version="4">
3
3
  <component name="ProjectModuleManager">
4
4
  <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/gb-dispatch.iml" filepath="$PROJECT_DIR$/.idea/gb-dispatch.iml" />
5
6
  <module fileurl="file://$PROJECT_DIR$/.idea/gb-dispatch.iml" filepath="$PROJECT_DIR$/.idea/gb-dispatch.iml" />
6
7
  <module fileurl="file://$PROJECT_DIR$/.idea/gb_dispatch.iml" filepath="$PROJECT_DIR$/.idea/gb_dispatch.iml" />
7
8
  </modules>
data/CHANGELOG.txt CHANGED
@@ -1,3 +1,10 @@
1
+ v0.1.0
2
+ - Added support for rails 5 - fixed deadlock issues.
3
+ - Added force_new_connection method to ActiveRecord connection pool for rails >= 5
4
+ v0.0.6
5
+ - Fixed bug with logger
6
+ v0.0.5
7
+ - Dropped celluloid - use concurrent-ruby as a backend
1
8
  v0.0.4
2
9
  - Compatible with celluloid version 17.3
3
10
  v0.0.3
data/Dockerfile ADDED
@@ -0,0 +1,12 @@
1
+ FROM ruby:2.5.1-alpine
2
+
3
+ RUN apk add --no-cache --update build-base \
4
+ linux-headers \
5
+ git
6
+
7
+ ENV APP_PATH /opt/project
8
+
9
+ # Different layer for gems installation
10
+ WORKDIR $APP_PATH
11
+ COPY . $APP_PATH
12
+ RUN bundle install --jobs `expr $(cat /proc/cpuinfo | grep -c "cpu cores") - 1` --retry 3
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
1
+ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in gb_dispatch.gemspec
4
4
  gemspec
data/Gemfile.lock CHANGED
@@ -1,37 +1,37 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gb_dispatch (0.0.5)
4
+ gb_dispatch (0.1.0)
5
5
  concurrent-ruby (~> 1.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- concurrent-ruby (1.0.0)
11
- concurrent-ruby-ext (1.0.0)
12
- concurrent-ruby (~> 1.0.0)
13
- diff-lcs (1.2.5)
14
- docile (1.1.5)
15
- json (1.8.3)
10
+ concurrent-ruby (1.0.5)
11
+ concurrent-ruby-ext (1.0.5)
12
+ concurrent-ruby (= 1.0.5)
13
+ diff-lcs (1.3)
14
+ docile (1.3.1)
15
+ json (2.1.0)
16
16
  rake (10.5.0)
17
- rspec (3.4.0)
18
- rspec-core (~> 3.4.0)
19
- rspec-expectations (~> 3.4.0)
20
- rspec-mocks (~> 3.4.0)
21
- rspec-core (3.4.1)
22
- rspec-support (~> 3.4.0)
23
- rspec-expectations (3.4.0)
17
+ rspec (3.7.0)
18
+ rspec-core (~> 3.7.0)
19
+ rspec-expectations (~> 3.7.0)
20
+ rspec-mocks (~> 3.7.0)
21
+ rspec-core (3.7.1)
22
+ rspec-support (~> 3.7.0)
23
+ rspec-expectations (3.7.0)
24
24
  diff-lcs (>= 1.2.0, < 2.0)
25
- rspec-support (~> 3.4.0)
26
- rspec-mocks (3.4.1)
25
+ rspec-support (~> 3.7.0)
26
+ rspec-mocks (3.7.0)
27
27
  diff-lcs (>= 1.2.0, < 2.0)
28
- rspec-support (~> 3.4.0)
29
- rspec-support (3.4.1)
30
- simplecov (0.11.1)
31
- docile (~> 1.1.0)
32
- json (~> 1.8)
28
+ rspec-support (~> 3.7.0)
29
+ rspec-support (3.7.1)
30
+ simplecov (0.16.1)
31
+ docile (~> 1.1)
32
+ json (>= 1.8, < 3)
33
33
  simplecov-html (~> 0.10.0)
34
- simplecov-html (0.10.0)
34
+ simplecov-html (0.10.2)
35
35
 
36
36
  PLATFORMS
37
37
  ruby
@@ -43,3 +43,6 @@ DEPENDENCIES
43
43
  rake (~> 10.0)
44
44
  rspec
45
45
  simplecov
46
+
47
+ BUNDLED WITH
48
+ 1.16.1
@@ -0,0 +1,17 @@
1
+ if defined?(ActiveRecord)
2
+ module ActiveRecord
3
+ module ConnectionAdapters
4
+ class ConnectionPool
5
+ def force_new_connection
6
+ old_lock = @lock_thread
7
+ @lock_thread = nil
8
+ with_connection do |conn|
9
+ yield conn
10
+ end
11
+ ensure
12
+ @lock_thread = old_lock
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -21,13 +21,22 @@ module GBDispatch
21
21
  def perform_now(block=nil)
22
22
  Thread.current[:name] ||= name
23
23
  if defined?(Rails) && defined?(ActiveRecord::Base)
24
+ require 'gb_dispatch/active_record_patch'
24
25
  thread_block = ->() do
25
- begin
26
- ActiveRecord::Base.connection_pool.with_connection do
27
- block ? block.call : yield
26
+ if Rails::VERSION::MAJOR < 5
27
+ begin
28
+ ActiveRecord::Base.connection_pool.force_new_connection do
29
+ block ? block.call : yield
30
+ end
31
+ ensure
32
+ ActiveRecord::Base.clear_active_connections!
33
+ end
34
+ else
35
+ Rails.application.executor.wrap do
36
+ ActiveRecord::Base.connection_pool.force_new_connection do
37
+ block ? block.call : yield
38
+ end
28
39
  end
29
- ensure
30
- ActiveRecord::Base.clear_active_connections!
31
40
  end
32
41
  end
33
42
  else
@@ -29,20 +29,22 @@ module GBDispatch
29
29
  # @param options [Hash]
30
30
  # @option options [String] :name queue name used for debugging and better logging.
31
31
  def execute(block, options=Hash.new)
32
- future = Concurrent::Future.new(:executor => self.pool) do
33
- begin
34
- name = options[:name]
35
- Thread.current[:name] ||= name if name
36
- result = block.call
37
- result
38
- rescue Exception => e
39
- if defined?(Opbeat)
40
- Opbeat.set_context extra: {queue: name} if name
41
- Opbeat.capture_exception(e)
42
- end
43
- GBDispatch.logger.error "Failed execution of queue #{name} with error #{e.message}"
44
- raise e
32
+ if defined?(Rails) && defined?(Rails::VERSION::MAJOR)
33
+ if Rails::VERSION::MAJOR < 5
34
+ _execute(block, options)
35
+ else
36
+ _execute_rails(block, options)
45
37
  end
38
+ else
39
+ _execute(block, options)
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ def _execute(block, options)
46
+ future = Concurrent::Future.new(:executor => self.pool) do
47
+ _run_block(block, options)
46
48
  end
47
49
  future.execute
48
50
  future.value
@@ -51,6 +53,43 @@ module GBDispatch
51
53
  end
52
54
  future.value
53
55
  end
56
+
57
+ def _execute_rails(block, options)
58
+ if defined?(Rails) && defined?(ActiveSupport::Dependencies)
59
+ future = Concurrent::Future.new(:executor => self.pool) do
60
+ Rails.application.executor.wrap do
61
+ ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
62
+ _run_block(block, options)
63
+ end
64
+ end
65
+ end
66
+ future.execute
67
+ ActiveSupport::Dependencies.interlock.permit_concurrent_loads { future.value }
68
+ if future.rejected?
69
+ raise future.reason
70
+ end
71
+ future.value
72
+ else
73
+ raise 'Failed loading rails!'
74
+ end
75
+ end
76
+
77
+ def _run_block(block, options)
78
+ begin
79
+ name = options[:name]
80
+ Thread.current[:name] ||= name if name
81
+ result = block.call
82
+ result
83
+ rescue Exception => e
84
+ if defined?(Raven)
85
+ Raven.tags_context :gb_dispacth => true
86
+ Raven.extra_context :dispatch_queue => name
87
+ Raven.capture_exception(e)
88
+ end
89
+ GBDispatch.logger.error "Failed execution of queue #{name} with error #{e.message}"
90
+ raise e
91
+ end
92
+ end
54
93
  end
55
94
  end
56
95
  end
@@ -1,3 +1,3 @@
1
1
  module GBDispatch
2
- VERSION = '0.0.6'
2
+ VERSION = '0.1.0'
3
3
  end
@@ -65,6 +65,7 @@ describe GBDispatch do
65
65
  GBDispatch.dispatch_after 0.1, :test do
66
66
  a << 1
67
67
  end
68
+ sleep(0.01)
68
69
  expect(a.empty?).to be_truthy
69
70
  sleep(0.15)
70
71
  expect(a).to eq [1]
@@ -75,6 +76,7 @@ describe GBDispatch do
75
76
  GBDispatch.dispatch_after_on_queue 0.1, :test do
76
77
  a << 1
77
78
  end
79
+ sleep(0.01)
78
80
  expect(a.empty?).to be_truthy
79
81
  sleep(0.2)
80
82
  expect(a).to eq [1]
data/spec/queue_spec.rb CHANGED
@@ -85,6 +85,9 @@ describe GBDispatch::Queue do
85
85
  context 'rails' do
86
86
  before(:each) do
87
87
  class Rails
88
+ module VERSION
89
+ MAJOR = 4
90
+ end
88
91
  end
89
92
  module ActiveRecord
90
93
  class Base
@@ -92,6 +95,12 @@ describe GBDispatch::Queue do
92
95
  def with_connection
93
96
  yield
94
97
  end
98
+
99
+ def force_new_connection
100
+ with_connection do
101
+ yield
102
+ end
103
+ end
95
104
  end
96
105
 
97
106
  def self.connection_pool
data/spec/spec_helper.rb CHANGED
@@ -22,7 +22,7 @@ SimpleCov.start do
22
22
  add_filter '/spec/'
23
23
  end
24
24
 
25
- SimpleCov.minimum_coverage 90
25
+ SimpleCov.minimum_coverage 78
26
26
 
27
27
  RSpec.configure do |config|
28
28
  # rspec-expectations config goes here. You can use an alternate
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gb_dispatch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kacper Kawecki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-19 00:00:00.000000000 Z
11
+ date: 2018-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -96,6 +96,7 @@ files:
96
96
  - ".idea/vcs.xml"
97
97
  - ".rspec"
98
98
  - CHANGELOG.txt
99
+ - Dockerfile
99
100
  - Gemfile
100
101
  - Gemfile.lock
101
102
  - LICENSE.txt
@@ -103,6 +104,7 @@ files:
103
104
  - Rakefile
104
105
  - gb_dispatch.gemspec
105
106
  - lib/gb_dispatch.rb
107
+ - lib/gb_dispatch/active_record_patch.rb
106
108
  - lib/gb_dispatch/central_dispatch.rb
107
109
  - lib/gb_dispatch/manager.rb
108
110
  - lib/gb_dispatch/queue.rb
@@ -132,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
134
  version: '0'
133
135
  requirements: []
134
136
  rubyforge_project:
135
- rubygems_version: 2.4.8
137
+ rubygems_version: 2.7.6
136
138
  signing_key:
137
139
  specification_version: 4
138
140
  summary: GCD emulation for ruby
@@ -141,4 +143,3 @@ test_files:
141
143
  - spec/queue_spec.rb
142
144
  - spec/runner_spec.rb
143
145
  - spec/spec_helper.rb
144
- has_rdoc: