bundler 2.2.16 → 2.4.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +971 -7
- data/README.md +4 -7
- data/bundler.gemspec +10 -13
- data/exe/bundle +12 -24
- data/exe/bundler +1 -1
- data/lib/bundler/.document +1 -0
- data/lib/bundler/build_metadata.rb +3 -3
- data/lib/bundler/cli/add.rb +1 -1
- data/lib/bundler/cli/binstubs.rb +6 -2
- data/lib/bundler/cli/cache.rb +1 -1
- data/lib/bundler/cli/check.rb +5 -3
- data/lib/bundler/cli/common.rb +6 -2
- data/lib/bundler/cli/config.rb +10 -1
- data/lib/bundler/cli/console.rb +2 -2
- data/lib/bundler/cli/doctor.rb +22 -5
- data/lib/bundler/cli/exec.rb +1 -6
- data/lib/bundler/cli/gem.rb +147 -35
- data/lib/bundler/cli/info.rb +28 -7
- data/lib/bundler/cli/init.rb +6 -2
- data/lib/bundler/cli/install.rb +26 -58
- data/lib/bundler/cli/issue.rb +4 -3
- data/lib/bundler/cli/list.rb +7 -1
- data/lib/bundler/cli/lock.rb +11 -4
- data/lib/bundler/cli/open.rb +7 -6
- data/lib/bundler/cli/outdated.rb +23 -17
- data/lib/bundler/cli/platform.rb +8 -6
- data/lib/bundler/cli/remove.rb +1 -2
- data/lib/bundler/cli/show.rb +1 -1
- data/lib/bundler/cli/update.rb +17 -8
- data/lib/bundler/cli/viz.rb +1 -1
- data/lib/bundler/cli.rb +95 -65
- data/lib/bundler/compact_index_client/cache.rb +1 -10
- data/lib/bundler/compact_index_client/updater.rb +56 -43
- data/lib/bundler/compact_index_client.rb +2 -8
- data/lib/bundler/constants.rb +1 -1
- data/lib/bundler/current_ruby.rb +19 -6
- data/lib/bundler/definition.rb +386 -419
- data/lib/bundler/dependency.rb +24 -71
- data/lib/bundler/digest.rb +71 -0
- data/lib/bundler/dsl.rb +48 -63
- data/lib/bundler/endpoint_specification.rb +15 -13
- data/lib/bundler/env.rb +3 -3
- data/lib/bundler/environment_preserver.rb +7 -3
- data/lib/bundler/errors.rb +30 -14
- data/lib/bundler/feature_flag.rb +0 -5
- data/lib/bundler/fetcher/base.rb +6 -8
- data/lib/bundler/fetcher/compact_index.rb +21 -28
- data/lib/bundler/fetcher/dependency.rb +2 -6
- data/lib/bundler/fetcher/downloader.rb +12 -10
- data/lib/bundler/fetcher/index.rb +1 -29
- data/lib/bundler/fetcher.rb +35 -30
- data/lib/bundler/force_platform.rb +18 -0
- data/lib/bundler/friendly_errors.rb +26 -39
- data/lib/bundler/gem_helper.rb +10 -22
- data/lib/bundler/gem_helpers.rb +9 -2
- data/lib/bundler/gem_version_promoter.rb +53 -98
- data/lib/bundler/graph.rb +3 -3
- data/lib/bundler/index.rb +14 -57
- data/lib/bundler/injector.rb +20 -6
- data/lib/bundler/inline.rb +10 -22
- data/lib/bundler/installer/gem_installer.rb +16 -21
- data/lib/bundler/installer/parallel_installer.rb +4 -34
- data/lib/bundler/installer/standalone.rb +53 -17
- data/lib/bundler/installer.rb +26 -58
- data/lib/bundler/lazy_specification.rb +72 -55
- data/lib/bundler/lockfile_generator.rb +3 -3
- data/lib/bundler/lockfile_parser.rb +31 -45
- data/lib/bundler/man/bundle-add.1 +21 -5
- data/lib/bundler/man/bundle-add.1.ronn +16 -4
- data/lib/bundler/man/bundle-binstubs.1 +1 -1
- data/lib/bundler/man/bundle-cache.1 +9 -3
- data/lib/bundler/man/bundle-cache.1.ronn +9 -2
- data/lib/bundler/man/bundle-check.1 +1 -1
- data/lib/bundler/man/bundle-clean.1 +2 -2
- data/lib/bundler/man/bundle-clean.1.ronn +1 -1
- data/lib/bundler/man/bundle-config.1 +50 -26
- data/lib/bundler/man/bundle-config.1.ronn +47 -32
- data/lib/bundler/man/bundle-console.1 +53 -0
- data/lib/bundler/man/bundle-console.1.ronn +44 -0
- data/lib/bundler/man/bundle-doctor.1 +1 -1
- data/lib/bundler/man/bundle-exec.1 +6 -6
- data/lib/bundler/man/bundle-exec.1.ronn +6 -6
- data/lib/bundler/man/bundle-gem.1 +37 -34
- data/lib/bundler/man/bundle-gem.1.ronn +21 -5
- data/lib/bundler/man/bundle-help.1 +13 -0
- data/lib/bundler/man/bundle-help.1.ronn +12 -0
- data/lib/bundler/man/bundle-info.1 +3 -3
- data/lib/bundler/man/bundle-info.1.ronn +3 -3
- data/lib/bundler/man/bundle-init.1 +5 -1
- data/lib/bundler/man/bundle-init.1.ronn +2 -0
- data/lib/bundler/man/bundle-inject.1 +5 -2
- data/lib/bundler/man/bundle-inject.1.ronn +3 -1
- data/lib/bundler/man/bundle-install.1 +6 -31
- data/lib/bundler/man/bundle-install.1.ronn +8 -31
- data/lib/bundler/man/bundle-list.1 +1 -1
- data/lib/bundler/man/bundle-lock.1 +1 -1
- data/lib/bundler/man/bundle-open.1 +22 -2
- data/lib/bundler/man/bundle-open.1.ronn +9 -1
- data/lib/bundler/man/bundle-outdated.1 +15 -18
- data/lib/bundler/man/bundle-outdated.1.ronn +13 -19
- data/lib/bundler/man/bundle-platform.1 +16 -6
- data/lib/bundler/man/bundle-platform.1.ronn +14 -7
- data/lib/bundler/man/bundle-plugin.1 +81 -0
- data/lib/bundler/man/bundle-plugin.1.ronn +59 -0
- data/lib/bundler/man/bundle-pristine.1 +1 -1
- data/lib/bundler/man/bundle-remove.1 +1 -1
- data/lib/bundler/man/bundle-show.1 +1 -1
- data/lib/bundler/man/bundle-update.1 +5 -5
- data/lib/bundler/man/bundle-update.1.ronn +5 -4
- data/lib/bundler/man/bundle-version.1 +35 -0
- data/lib/bundler/man/bundle-version.1.ronn +24 -0
- data/lib/bundler/man/bundle-viz.1 +4 -1
- data/lib/bundler/man/bundle-viz.1.ronn +2 -0
- data/lib/bundler/man/bundle.1 +15 -10
- data/lib/bundler/man/bundle.1.ronn +12 -7
- data/lib/bundler/man/gemfile.5 +131 -81
- data/lib/bundler/man/gemfile.5.ronn +111 -85
- data/lib/bundler/man/index.txt +4 -0
- data/lib/bundler/match_metadata.rb +13 -0
- data/lib/bundler/match_platform.rb +0 -1
- data/lib/bundler/match_remote_metadata.rb +29 -0
- data/lib/bundler/mirror.rb +5 -7
- data/lib/bundler/plugin/api/source.rb +17 -8
- data/lib/bundler/plugin/index.rb +9 -6
- data/lib/bundler/plugin/installer/git.rb +0 -4
- data/lib/bundler/plugin/installer/rubygems.rb +0 -8
- data/lib/bundler/plugin/installer.rb +9 -4
- data/lib/bundler/plugin.rb +30 -9
- data/lib/bundler/process_lock.rb +1 -1
- data/lib/bundler/remote_specification.rb +7 -5
- data/lib/bundler/resolver/base.rb +107 -0
- data/lib/bundler/resolver/candidate.rb +94 -0
- data/lib/bundler/resolver/incompatibility.rb +15 -0
- data/lib/bundler/resolver/package.rb +72 -0
- data/lib/bundler/resolver/root.rb +25 -0
- data/lib/bundler/resolver/spec_group.rb +42 -94
- data/lib/bundler/resolver.rb +331 -381
- data/lib/bundler/retry.rb +1 -1
- data/lib/bundler/ruby_dsl.rb +7 -1
- data/lib/bundler/ruby_version.rb +8 -21
- data/lib/bundler/rubygems_ext.rb +175 -34
- data/lib/bundler/rubygems_gem_installer.rb +46 -14
- data/lib/bundler/rubygems_integration.rb +57 -108
- data/lib/bundler/runtime.rb +20 -18
- data/lib/bundler/safe_marshal.rb +31 -0
- data/lib/bundler/self_manager.rb +168 -0
- data/lib/bundler/settings.rb +101 -30
- data/lib/bundler/setup.rb +5 -2
- data/lib/bundler/shared_helpers.rb +17 -32
- data/lib/bundler/source/git/git_proxy.rb +242 -77
- data/lib/bundler/source/git.rb +82 -41
- data/lib/bundler/source/metadata.rb +3 -4
- data/lib/bundler/source/path/installer.rb +1 -22
- data/lib/bundler/source/path.rb +7 -7
- data/lib/bundler/source/rubygems.rb +158 -212
- data/lib/bundler/source/rubygems_aggregate.rb +68 -0
- data/lib/bundler/source.rb +19 -5
- data/lib/bundler/source_list.rb +91 -52
- data/lib/bundler/source_map.rb +71 -0
- data/lib/bundler/spec_set.rb +69 -57
- data/lib/bundler/stub_specification.rb +5 -3
- data/lib/bundler/templates/Executable +3 -5
- data/lib/bundler/templates/Executable.bundler +11 -16
- data/lib/bundler/templates/Executable.standalone +4 -4
- data/lib/bundler/templates/Gemfile +0 -2
- data/lib/bundler/templates/newgem/Cargo.toml.tt +7 -0
- data/lib/bundler/templates/newgem/Gemfile.tt +8 -2
- data/lib/bundler/templates/newgem/README.md.tt +7 -11
- data/lib/bundler/templates/newgem/Rakefile.tt +27 -3
- data/lib/bundler/templates/newgem/bin/console.tt +0 -4
- data/lib/bundler/templates/newgem/circleci/config.yml.tt +12 -0
- data/lib/bundler/templates/newgem/ext/newgem/Cargo.toml.tt +15 -0
- data/lib/bundler/templates/newgem/ext/newgem/extconf-c.rb.tt +10 -0
- data/lib/bundler/templates/newgem/ext/newgem/extconf-rust.rb.tt +6 -0
- data/lib/bundler/templates/newgem/ext/newgem/newgem.c.tt +1 -1
- data/lib/bundler/templates/newgem/ext/newgem/src/lib.rs.tt +12 -0
- data/lib/bundler/templates/newgem/github/workflows/main.yml.tt +24 -3
- data/lib/bundler/templates/newgem/gitignore.tt +3 -0
- data/lib/bundler/templates/newgem/gitlab-ci.yml.tt +13 -4
- data/lib/bundler/templates/newgem/newgem.gemspec.tt +27 -18
- data/lib/bundler/templates/newgem/sig/newgem.rbs.tt +8 -0
- data/lib/bundler/templates/newgem/standard.yml.tt +3 -0
- data/lib/bundler/templates/newgem/test/minitest/{newgem_test.rb.tt → test_newgem.rb.tt} +1 -1
- data/lib/bundler/ui/rg_proxy.rb +1 -1
- data/lib/bundler/ui/shell.rb +36 -13
- data/lib/bundler/ui/silent.rb +21 -5
- data/lib/bundler/uri_normalizer.rb +23 -0
- data/lib/bundler/vendor/.document +1 -0
- data/lib/bundler/vendor/connection_pool/LICENSE +20 -0
- data/lib/bundler/vendor/connection_pool/lib/connection_pool/timed_stack.rb +19 -21
- data/lib/bundler/vendor/connection_pool/lib/connection_pool/version.rb +1 -1
- data/lib/bundler/vendor/connection_pool/lib/connection_pool/wrapper.rb +56 -0
- data/lib/bundler/vendor/connection_pool/lib/connection_pool.rb +41 -74
- data/lib/bundler/vendor/fileutils/LICENSE.txt +22 -0
- data/lib/bundler/vendor/fileutils/lib/fileutils.rb +1351 -409
- data/lib/bundler/vendor/net-http-persistent/README.rdoc +82 -0
- data/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent.rb +1 -1
- data/lib/bundler/vendor/pub_grub/LICENSE.txt +21 -0
- data/lib/bundler/vendor/pub_grub/lib/pub_grub/assignment.rb +20 -0
- data/lib/bundler/vendor/pub_grub/lib/pub_grub/basic_package_source.rb +189 -0
- data/lib/bundler/vendor/pub_grub/lib/pub_grub/failure_writer.rb +182 -0
- data/lib/bundler/vendor/pub_grub/lib/pub_grub/incompatibility.rb +150 -0
- data/lib/bundler/vendor/pub_grub/lib/pub_grub/package.rb +43 -0
- data/lib/bundler/vendor/pub_grub/lib/pub_grub/partial_solution.rb +121 -0
- data/lib/bundler/vendor/pub_grub/lib/pub_grub/rubygems.rb +45 -0
- data/lib/bundler/vendor/pub_grub/lib/pub_grub/solve_failure.rb +19 -0
- data/lib/bundler/vendor/pub_grub/lib/pub_grub/static_package_source.rb +60 -0
- data/lib/bundler/vendor/pub_grub/lib/pub_grub/term.rb +105 -0
- data/lib/bundler/vendor/pub_grub/lib/pub_grub/version.rb +3 -0
- data/lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb +129 -0
- data/lib/bundler/vendor/pub_grub/lib/pub_grub/version_range.rb +411 -0
- data/lib/bundler/vendor/pub_grub/lib/pub_grub/version_solver.rb +248 -0
- data/lib/bundler/vendor/pub_grub/lib/pub_grub/version_union.rb +178 -0
- data/lib/bundler/vendor/pub_grub/lib/pub_grub.rb +31 -0
- data/lib/bundler/vendor/thor/LICENSE.md +20 -0
- data/lib/bundler/vendor/thor/lib/thor/actions/file_manipulation.rb +5 -5
- data/lib/bundler/vendor/thor/lib/thor/actions/inject_into_file.rb +1 -2
- data/lib/bundler/vendor/thor/lib/thor/actions.rb +6 -2
- data/lib/bundler/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb +6 -0
- data/lib/bundler/vendor/thor/lib/thor/error.rb +9 -4
- data/lib/bundler/vendor/thor/lib/thor/parser/options.rb +19 -1
- data/lib/bundler/vendor/thor/lib/thor/shell/basic.rb +23 -5
- data/lib/bundler/vendor/thor/lib/thor/shell.rb +1 -1
- data/lib/bundler/vendor/thor/lib/thor/util.rb +1 -1
- data/lib/bundler/vendor/thor/lib/thor/version.rb +1 -1
- data/lib/bundler/vendor/tsort/LICENSE.txt +22 -0
- data/lib/bundler/vendor/tsort/lib/tsort.rb +452 -0
- data/lib/bundler/vendor/uri/LICENSE.txt +22 -0
- data/lib/bundler/vendor/uri/lib/uri/common.rb +76 -91
- data/lib/bundler/vendor/uri/lib/uri/file.rb +7 -1
- data/lib/bundler/vendor/uri/lib/uri/ftp.rb +2 -2
- data/lib/bundler/vendor/uri/lib/uri/generic.rb +32 -13
- data/lib/bundler/vendor/uri/lib/uri/http.rb +40 -3
- data/lib/bundler/vendor/uri/lib/uri/https.rb +2 -2
- data/lib/bundler/vendor/uri/lib/uri/ldap.rb +2 -2
- data/lib/bundler/vendor/uri/lib/uri/ldaps.rb +2 -1
- data/lib/bundler/vendor/uri/lib/uri/mailto.rb +2 -3
- data/lib/bundler/vendor/uri/lib/uri/rfc2396_parser.rb +16 -23
- data/lib/bundler/vendor/uri/lib/uri/rfc3986_parser.rb +12 -18
- data/lib/bundler/vendor/uri/lib/uri/version.rb +1 -1
- data/lib/bundler/vendor/uri/lib/uri/ws.rb +83 -0
- data/lib/bundler/vendor/uri/lib/uri/wss.rb +23 -0
- data/lib/bundler/vendor/uri/lib/uri.rb +3 -3
- data/lib/bundler/vendored_persistent.rb +1 -33
- data/lib/bundler/{vendored_molinillo.rb → vendored_pub_grub.rb} +1 -1
- data/lib/bundler/{vendored_tmpdir.rb → vendored_tsort.rb} +1 -1
- data/lib/bundler/version.rb +5 -1
- data/lib/bundler/worker.rb +24 -11
- data/lib/bundler.rb +66 -110
- metadata +70 -41
- data/lib/bundler/dep_proxy.rb +0 -55
- data/lib/bundler/gemdeps.rb +0 -29
- data/lib/bundler/psyched_yaml.rb +0 -22
- data/lib/bundler/templates/gems.rb +0 -8
- data/lib/bundler/templates/newgem/ext/newgem/extconf.rb.tt +0 -5
- data/lib/bundler/templates/newgem/travis.yml.tt +0 -6
- data/lib/bundler/vendor/connection_pool/lib/connection_pool/monotonic_time.rb +0 -66
- data/lib/bundler/vendor/molinillo/lib/molinillo/delegates/resolution_state.rb +0 -57
- data/lib/bundler/vendor/molinillo/lib/molinillo/delegates/specification_provider.rb +0 -88
- data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/action.rb +0 -36
- data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/add_edge_no_circular.rb +0 -66
- data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/add_vertex.rb +0 -62
- data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/delete_edge.rb +0 -63
- data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/detach_vertex_named.rb +0 -61
- data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/log.rb +0 -126
- data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/set_payload.rb +0 -46
- data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/tag.rb +0 -36
- data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb +0 -164
- data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb +0 -255
- data/lib/bundler/vendor/molinillo/lib/molinillo/errors.rb +0 -143
- data/lib/bundler/vendor/molinillo/lib/molinillo/gem_metadata.rb +0 -6
- data/lib/bundler/vendor/molinillo/lib/molinillo/modules/specification_provider.rb +0 -112
- data/lib/bundler/vendor/molinillo/lib/molinillo/modules/ui.rb +0 -67
- data/lib/bundler/vendor/molinillo/lib/molinillo/resolution.rb +0 -839
- data/lib/bundler/vendor/molinillo/lib/molinillo/resolver.rb +0 -46
- data/lib/bundler/vendor/molinillo/lib/molinillo/state.rb +0 -58
- data/lib/bundler/vendor/molinillo/lib/molinillo.rb +0 -11
- data/lib/bundler/vendor/tmpdir/lib/tmpdir.rb +0 -154
- data/lib/bundler/version_ranges.rb +0 -122
@@ -1,13 +1,3 @@
|
|
1
|
-
require 'thread'
|
2
|
-
require 'timeout'
|
3
|
-
require_relative 'monotonic_time'
|
4
|
-
|
5
|
-
##
|
6
|
-
# Raised when you attempt to retrieve a connection from a pool that has been
|
7
|
-
# shut down.
|
8
|
-
|
9
|
-
class Bundler::ConnectionPool::PoolShuttingDownError < RuntimeError; end
|
10
|
-
|
11
1
|
##
|
12
2
|
# The TimedStack manages a pool of homogeneous connections (or any resource
|
13
3
|
# you wish to manage). Connections are created lazily up to a given maximum
|
@@ -25,7 +15,7 @@ class Bundler::ConnectionPool::PoolShuttingDownError < RuntimeError; end
|
|
25
15
|
#
|
26
16
|
# conn = ts.pop
|
27
17
|
# ts.pop timeout: 5
|
28
|
-
# #=> raises
|
18
|
+
# #=> raises Bundler::ConnectionPool::TimeoutError after 5 seconds
|
29
19
|
|
30
20
|
class Bundler::ConnectionPool::TimedStack
|
31
21
|
attr_reader :max
|
@@ -39,8 +29,8 @@ class Bundler::ConnectionPool::TimedStack
|
|
39
29
|
@created = 0
|
40
30
|
@que = []
|
41
31
|
@max = size
|
42
|
-
@mutex = Mutex.new
|
43
|
-
@resource = ConditionVariable.new
|
32
|
+
@mutex = Thread::Mutex.new
|
33
|
+
@resource = Thread::ConditionVariable.new
|
44
34
|
@shutdown_block = nil
|
45
35
|
end
|
46
36
|
|
@@ -64,7 +54,7 @@ class Bundler::ConnectionPool::TimedStack
|
|
64
54
|
##
|
65
55
|
# Retrieves a connection from the stack. If a connection is available it is
|
66
56
|
# immediately returned. If no connection is available within the given
|
67
|
-
# timeout a
|
57
|
+
# timeout a Bundler::ConnectionPool::TimeoutError is raised.
|
68
58
|
#
|
69
59
|
# +:timeout+ is the only checked entry in +options+ and is preferred over
|
70
60
|
# the +timeout+ argument (which will be removed in a future release). Other
|
@@ -74,7 +64,7 @@ class Bundler::ConnectionPool::TimedStack
|
|
74
64
|
options, timeout = timeout, 0.5 if Hash === timeout
|
75
65
|
timeout = options.fetch :timeout, timeout
|
76
66
|
|
77
|
-
deadline =
|
67
|
+
deadline = current_time + timeout
|
78
68
|
@mutex.synchronize do
|
79
69
|
loop do
|
80
70
|
raise Bundler::ConnectionPool::PoolShuttingDownError if @shutdown_block
|
@@ -83,25 +73,28 @@ class Bundler::ConnectionPool::TimedStack
|
|
83
73
|
connection = try_create(options)
|
84
74
|
return connection if connection
|
85
75
|
|
86
|
-
to_wait = deadline -
|
87
|
-
raise
|
76
|
+
to_wait = deadline - current_time
|
77
|
+
raise Bundler::ConnectionPool::TimeoutError, "Waited #{timeout} sec, #{length}/#{@max} available" if to_wait <= 0
|
88
78
|
@resource.wait(@mutex, to_wait)
|
89
79
|
end
|
90
80
|
end
|
91
81
|
end
|
92
82
|
|
93
83
|
##
|
94
|
-
# Shuts down the TimedStack
|
95
|
-
#
|
84
|
+
# Shuts down the TimedStack by passing each connection to +block+ and then
|
85
|
+
# removing it from the pool. Attempting to checkout a connection after
|
86
|
+
# shutdown will raise +Bundler::ConnectionPool::PoolShuttingDownError+ unless
|
87
|
+
# +:reload+ is +true+.
|
96
88
|
|
97
|
-
def shutdown(&block)
|
98
|
-
raise ArgumentError, "shutdown must receive a block" unless
|
89
|
+
def shutdown(reload: false, &block)
|
90
|
+
raise ArgumentError, "shutdown must receive a block" unless block
|
99
91
|
|
100
92
|
@mutex.synchronize do
|
101
93
|
@shutdown_block = block
|
102
94
|
@resource.broadcast
|
103
95
|
|
104
96
|
shutdown_connections
|
97
|
+
@shutdown_block = nil if reload
|
105
98
|
end
|
106
99
|
end
|
107
100
|
|
@@ -121,6 +114,10 @@ class Bundler::ConnectionPool::TimedStack
|
|
121
114
|
|
122
115
|
private
|
123
116
|
|
117
|
+
def current_time
|
118
|
+
Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
119
|
+
end
|
120
|
+
|
124
121
|
##
|
125
122
|
# This is an extension point for TimedStack and is called with a mutex.
|
126
123
|
#
|
@@ -149,6 +146,7 @@ class Bundler::ConnectionPool::TimedStack
|
|
149
146
|
conn = fetch_connection(options)
|
150
147
|
@shutdown_block.call(conn)
|
151
148
|
end
|
149
|
+
@created = 0
|
152
150
|
end
|
153
151
|
|
154
152
|
##
|
@@ -0,0 +1,56 @@
|
|
1
|
+
class Bundler::ConnectionPool
|
2
|
+
class Wrapper < ::BasicObject
|
3
|
+
METHODS = [:with, :pool_shutdown, :wrapped_pool]
|
4
|
+
|
5
|
+
def initialize(options = {}, &block)
|
6
|
+
@pool = options.fetch(:pool) { ::Bundler::ConnectionPool.new(options, &block) }
|
7
|
+
end
|
8
|
+
|
9
|
+
def wrapped_pool
|
10
|
+
@pool
|
11
|
+
end
|
12
|
+
|
13
|
+
def with(&block)
|
14
|
+
@pool.with(&block)
|
15
|
+
end
|
16
|
+
|
17
|
+
def pool_shutdown(&block)
|
18
|
+
@pool.shutdown(&block)
|
19
|
+
end
|
20
|
+
|
21
|
+
def pool_size
|
22
|
+
@pool.size
|
23
|
+
end
|
24
|
+
|
25
|
+
def pool_available
|
26
|
+
@pool.available
|
27
|
+
end
|
28
|
+
|
29
|
+
def respond_to?(id, *args)
|
30
|
+
METHODS.include?(id) || with { |c| c.respond_to?(id, *args) }
|
31
|
+
end
|
32
|
+
|
33
|
+
# rubocop:disable Style/MissingRespondToMissing
|
34
|
+
if ::RUBY_VERSION >= "3.0.0"
|
35
|
+
def method_missing(name, *args, **kwargs, &block)
|
36
|
+
with do |connection|
|
37
|
+
connection.send(name, *args, **kwargs, &block)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
elsif ::RUBY_VERSION >= "2.7.0"
|
41
|
+
ruby2_keywords def method_missing(name, *args, &block)
|
42
|
+
with do |connection|
|
43
|
+
connection.send(name, *args, &block)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
else
|
47
|
+
def method_missing(name, *args, &block)
|
48
|
+
with do |connection|
|
49
|
+
connection.send(name, *args, &block)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
# rubocop:enable Style/MethodMissingSuper
|
54
|
+
# rubocop:enable Style/MissingRespondToMissing
|
55
|
+
end
|
56
|
+
end
|
@@ -1,14 +1,20 @@
|
|
1
|
-
|
2
|
-
require_relative
|
1
|
+
require "timeout"
|
2
|
+
require_relative "connection_pool/version"
|
3
3
|
|
4
|
+
class Bundler::ConnectionPool
|
5
|
+
class Error < ::RuntimeError; end
|
6
|
+
|
7
|
+
class PoolShuttingDownError < ::Bundler::ConnectionPool::Error; end
|
4
8
|
|
5
|
-
|
6
|
-
|
9
|
+
class TimeoutError < ::Timeout::Error; end
|
10
|
+
end
|
11
|
+
|
12
|
+
# Generic connection pool class for sharing a limited number of objects or network connections
|
13
|
+
# among many threads. Note: pool elements are lazily created.
|
7
14
|
#
|
8
15
|
# Example usage with block (faster):
|
9
16
|
#
|
10
17
|
# @pool = Bundler::ConnectionPool.new { Redis.new }
|
11
|
-
#
|
12
18
|
# @pool.with do |redis|
|
13
19
|
# redis.lpop('my-list') if redis.llen('my-list') > 0
|
14
20
|
# end
|
@@ -34,29 +40,23 @@ require_relative 'connection_pool/timed_stack'
|
|
34
40
|
class Bundler::ConnectionPool
|
35
41
|
DEFAULTS = {size: 5, timeout: 5}
|
36
42
|
|
37
|
-
class Error < RuntimeError
|
38
|
-
end
|
39
|
-
|
40
43
|
def self.wrap(options, &block)
|
41
44
|
Wrapper.new(options, &block)
|
42
45
|
end
|
43
46
|
|
44
47
|
def initialize(options = {}, &block)
|
45
|
-
raise ArgumentError,
|
48
|
+
raise ArgumentError, "Connection pool requires a block" unless block
|
46
49
|
|
47
50
|
options = DEFAULTS.merge(options)
|
48
51
|
|
49
|
-
@size = options.fetch(:size)
|
52
|
+
@size = Integer(options.fetch(:size))
|
50
53
|
@timeout = options.fetch(:timeout)
|
51
54
|
|
52
55
|
@available = TimedStack.new(@size, &block)
|
53
|
-
@key = :"
|
54
|
-
@key_count = :"
|
56
|
+
@key = :"pool-#{@available.object_id}"
|
57
|
+
@key_count = :"pool-#{@available.object_id}-count"
|
55
58
|
end
|
56
59
|
|
57
|
-
if Thread.respond_to?(:handle_interrupt)
|
58
|
-
|
59
|
-
# MRI
|
60
60
|
def with(options = {})
|
61
61
|
Thread.handle_interrupt(Exception => :never) do
|
62
62
|
conn = checkout(options)
|
@@ -69,28 +69,15 @@ if Thread.respond_to?(:handle_interrupt)
|
|
69
69
|
end
|
70
70
|
end
|
71
71
|
end
|
72
|
-
|
73
|
-
else
|
74
|
-
|
75
|
-
# jruby 1.7.x
|
76
|
-
def with(options = {})
|
77
|
-
conn = checkout(options)
|
78
|
-
begin
|
79
|
-
yield conn
|
80
|
-
ensure
|
81
|
-
checkin
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
end
|
72
|
+
alias_method :then, :with
|
86
73
|
|
87
74
|
def checkout(options = {})
|
88
75
|
if ::Thread.current[@key]
|
89
|
-
::Thread.current[@key_count]+= 1
|
76
|
+
::Thread.current[@key_count] += 1
|
90
77
|
::Thread.current[@key]
|
91
78
|
else
|
92
|
-
::Thread.current[@key_count]= 1
|
93
|
-
::Thread.current[@key]= @available.pop(options[:timeout] || @timeout)
|
79
|
+
::Thread.current[@key_count] = 1
|
80
|
+
::Thread.current[@key] = @available.pop(options[:timeout] || @timeout)
|
94
81
|
end
|
95
82
|
end
|
96
83
|
|
@@ -98,64 +85,44 @@ end
|
|
98
85
|
if ::Thread.current[@key]
|
99
86
|
if ::Thread.current[@key_count] == 1
|
100
87
|
@available.push(::Thread.current[@key])
|
101
|
-
::Thread.current[@key]= nil
|
88
|
+
::Thread.current[@key] = nil
|
89
|
+
::Thread.current[@key_count] = nil
|
102
90
|
else
|
103
|
-
::Thread.current[@key_count]-= 1
|
91
|
+
::Thread.current[@key_count] -= 1
|
104
92
|
end
|
105
93
|
else
|
106
|
-
raise Bundler::ConnectionPool::Error,
|
94
|
+
raise Bundler::ConnectionPool::Error, "no connections are checked out"
|
107
95
|
end
|
108
96
|
|
109
97
|
nil
|
110
98
|
end
|
111
99
|
|
100
|
+
##
|
101
|
+
# Shuts down the Bundler::ConnectionPool by passing each connection to +block+ and
|
102
|
+
# then removing it from the pool. Attempting to checkout a connection after
|
103
|
+
# shutdown will raise +Bundler::ConnectionPool::PoolShuttingDownError+.
|
104
|
+
|
112
105
|
def shutdown(&block)
|
113
106
|
@available.shutdown(&block)
|
114
107
|
end
|
115
108
|
|
116
|
-
|
117
|
-
|
118
|
-
|
109
|
+
##
|
110
|
+
# Reloads the Bundler::ConnectionPool by passing each connection to +block+ and then
|
111
|
+
# removing it the pool. Subsequent checkouts will create new connections as
|
112
|
+
# needed.
|
113
|
+
|
114
|
+
def reload(&block)
|
115
|
+
@available.shutdown(reload: true, &block)
|
119
116
|
end
|
120
117
|
|
118
|
+
# Size of this connection pool
|
119
|
+
attr_reader :size
|
120
|
+
|
121
121
|
# Number of pool entries available for checkout at this instant.
|
122
122
|
def available
|
123
123
|
@available.length
|
124
124
|
end
|
125
|
-
|
126
|
-
private
|
127
|
-
|
128
|
-
class Wrapper < ::BasicObject
|
129
|
-
METHODS = [:with, :pool_shutdown]
|
130
|
-
|
131
|
-
def initialize(options = {}, &block)
|
132
|
-
@pool = options.fetch(:pool) { ::Bundler::ConnectionPool.new(options, &block) }
|
133
|
-
end
|
134
|
-
|
135
|
-
def with(&block)
|
136
|
-
@pool.with(&block)
|
137
|
-
end
|
138
|
-
|
139
|
-
def pool_shutdown(&block)
|
140
|
-
@pool.shutdown(&block)
|
141
|
-
end
|
142
|
-
|
143
|
-
def pool_size
|
144
|
-
@pool.size
|
145
|
-
end
|
146
|
-
|
147
|
-
def pool_available
|
148
|
-
@pool.available
|
149
|
-
end
|
150
|
-
|
151
|
-
def respond_to?(id, *args)
|
152
|
-
METHODS.include?(id) || with { |c| c.respond_to?(id, *args) }
|
153
|
-
end
|
154
|
-
|
155
|
-
def method_missing(name, *args, &block)
|
156
|
-
with do |connection|
|
157
|
-
connection.send(name, *args, &block)
|
158
|
-
end
|
159
|
-
end
|
160
|
-
end
|
161
125
|
end
|
126
|
+
|
127
|
+
require_relative "connection_pool/timed_stack"
|
128
|
+
require_relative "connection_pool/wrapper"
|
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (C) 1993-2013 Yukihiro Matsumoto. All rights reserved.
|
2
|
+
|
3
|
+
Redistribution and use in source and binary forms, with or without
|
4
|
+
modification, are permitted provided that the following conditions
|
5
|
+
are met:
|
6
|
+
1. Redistributions of source code must retain the above copyright
|
7
|
+
notice, this list of conditions and the following disclaimer.
|
8
|
+
2. Redistributions in binary form must reproduce the above copyright
|
9
|
+
notice, this list of conditions and the following disclaimer in the
|
10
|
+
documentation and/or other materials provided with the distribution.
|
11
|
+
|
12
|
+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
13
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
14
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
15
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
16
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
17
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
18
|
+
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
19
|
+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
20
|
+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
21
|
+
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
22
|
+
SUCH DAMAGE.
|