umbrellio-utils 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +2 -3
- data/.rubocop.yml +1 -1
- data/Gemfile.lock +75 -63
- data/lib/umbrellio_utils/database.rb +23 -8
- data/lib/umbrellio_utils/request_wrapper.rb +1 -1
- data/lib/umbrellio_utils/version.rb +1 -1
- data/umbrellio_utils.gemspec +2 -1
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c467440e60fca9a678c36cf4ef98a64bf907d6255ab125fa49c1c5a7bebcc58c
|
4
|
+
data.tar.gz: ae937f7096cd4cc0facc940990cfffd0263cf16d8f568628cef84fd78d36d4cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd966392f19e67cf5c7fbc36d9b2e5add185160d6cc7d3679efa6d3a40884eec37f83467af847b29bc14ddc8cced216e39402b6c645abcb6811162e7f59ad3cc
|
7
|
+
data.tar.gz: fbaad56491705678f219b645f535e4a409d42007ccdbbe6aaaa4f6c76f79e48f48132e44fea3d98952636d72cc1f9f0ea0465328feed1998170faf04448b50b2
|
data/.github/workflows/test.yml
CHANGED
@@ -16,7 +16,7 @@ jobs:
|
|
16
16
|
- uses: actions/checkout@v2
|
17
17
|
- uses: ruby/setup-ruby@v1
|
18
18
|
with:
|
19
|
-
ruby-version: 3
|
19
|
+
ruby-version: "3.1"
|
20
20
|
bundler-cache: true
|
21
21
|
- name: Run Linter
|
22
22
|
run: bundle exec ci-helper RubocopLint
|
@@ -42,8 +42,7 @@ jobs:
|
|
42
42
|
strategy:
|
43
43
|
fail-fast: false
|
44
44
|
matrix:
|
45
|
-
ruby: [2.
|
46
|
-
|
45
|
+
ruby: ["2.7", "3.0"]
|
47
46
|
|
48
47
|
steps:
|
49
48
|
- uses: actions/checkout@v2
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,127 +1,138 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
umbrellio-utils (0.
|
4
|
+
umbrellio-utils (0.5.0)
|
5
5
|
memery (~> 1)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activesupport (
|
10
|
+
activesupport (7.0.3.1)
|
11
11
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
12
12
|
i18n (>= 1.6, < 2)
|
13
13
|
minitest (>= 5.1)
|
14
14
|
tzinfo (~> 2.0)
|
15
|
-
|
15
|
+
amazing_print (1.4.0)
|
16
16
|
ast (2.4.2)
|
17
|
-
|
18
|
-
bundler-audit (0.9.0.1)
|
17
|
+
bundler-audit (0.9.1)
|
19
18
|
bundler (>= 1.2.0, < 3)
|
20
19
|
thor (~> 1.0)
|
21
|
-
ci-helper (0.
|
20
|
+
ci-helper (0.5.0)
|
22
21
|
colorize (~> 0.8)
|
23
22
|
dry-inflector (~> 0.2)
|
24
23
|
umbrellio-sequel-plugins (~> 0.4)
|
25
24
|
coderay (1.1.3)
|
26
25
|
colorize (0.8.1)
|
27
|
-
concurrent-ruby (1.1.
|
28
|
-
diff-lcs (1.
|
26
|
+
concurrent-ruby (1.1.10)
|
27
|
+
diff-lcs (1.5.0)
|
29
28
|
docile (1.4.0)
|
30
|
-
dry-inflector (0.
|
31
|
-
i18n (1.
|
29
|
+
dry-inflector (0.3.0)
|
30
|
+
i18n (1.12.0)
|
32
31
|
concurrent-ruby (~> 1.0)
|
33
|
-
json (2.6.
|
32
|
+
json (2.6.2)
|
34
33
|
memery (1.4.1)
|
35
34
|
ruby2_keywords (~> 0.0.2)
|
36
35
|
method_source (1.0.0)
|
37
|
-
|
38
|
-
|
36
|
+
mini_portile2 (2.8.0)
|
37
|
+
minitest (5.16.2)
|
38
|
+
nokogiri (1.13.8)
|
39
|
+
mini_portile2 (~> 2.8.0)
|
40
|
+
racc (~> 1.4)
|
41
|
+
nokogiri (1.13.8-arm64-darwin)
|
42
|
+
racc (~> 1.4)
|
43
|
+
nokogiri (1.13.8-x86_64-darwin)
|
44
|
+
racc (~> 1.4)
|
45
|
+
nokogiri (1.13.8-x86_64-linux)
|
39
46
|
racc (~> 1.4)
|
40
47
|
nori (2.6.0)
|
41
|
-
parallel (1.
|
42
|
-
parser (3.
|
48
|
+
parallel (1.22.1)
|
49
|
+
parser (3.1.2.0)
|
43
50
|
ast (~> 2.4.1)
|
44
51
|
pry (0.14.1)
|
45
52
|
coderay (~> 1.1)
|
46
53
|
method_source (~> 1.0)
|
47
54
|
racc (1.6.0)
|
48
|
-
rack (2.2.
|
49
|
-
rainbow (3.
|
55
|
+
rack (2.2.4)
|
56
|
+
rainbow (3.1.1)
|
50
57
|
rake (13.0.6)
|
51
|
-
regexp_parser (2.
|
58
|
+
regexp_parser (2.5.0)
|
52
59
|
rexml (3.2.5)
|
53
|
-
rspec (3.
|
54
|
-
rspec-core (~> 3.
|
55
|
-
rspec-expectations (~> 3.
|
56
|
-
rspec-mocks (~> 3.
|
57
|
-
rspec-core (3.
|
58
|
-
rspec-support (~> 3.
|
59
|
-
rspec-expectations (3.
|
60
|
+
rspec (3.11.0)
|
61
|
+
rspec-core (~> 3.11.0)
|
62
|
+
rspec-expectations (~> 3.11.0)
|
63
|
+
rspec-mocks (~> 3.11.0)
|
64
|
+
rspec-core (3.11.0)
|
65
|
+
rspec-support (~> 3.11.0)
|
66
|
+
rspec-expectations (3.11.0)
|
60
67
|
diff-lcs (>= 1.2.0, < 2.0)
|
61
|
-
rspec-support (~> 3.
|
62
|
-
rspec-json_matcher (0.
|
63
|
-
|
68
|
+
rspec-support (~> 3.11.0)
|
69
|
+
rspec-json_matcher (0.2.0)
|
70
|
+
amazing_print
|
64
71
|
json
|
65
|
-
rspec-mocks (3.
|
72
|
+
rspec-mocks (3.11.1)
|
66
73
|
diff-lcs (>= 1.2.0, < 2.0)
|
67
|
-
rspec-support (~> 3.
|
68
|
-
rspec-support (3.
|
69
|
-
rubocop (1.
|
74
|
+
rspec-support (~> 3.11.0)
|
75
|
+
rspec-support (3.11.0)
|
76
|
+
rubocop (1.30.1)
|
70
77
|
parallel (~> 1.10)
|
71
|
-
parser (>= 3.
|
78
|
+
parser (>= 3.1.0.0)
|
72
79
|
rainbow (>= 2.2.2, < 4.0)
|
73
80
|
regexp_parser (>= 1.8, < 3.0)
|
74
|
-
rexml
|
75
|
-
rubocop-ast (>= 1.
|
81
|
+
rexml (>= 3.2.5, < 4.0)
|
82
|
+
rubocop-ast (>= 1.18.0, < 2.0)
|
76
83
|
ruby-progressbar (~> 1.7)
|
77
84
|
unicode-display_width (>= 1.4.0, < 3.0)
|
78
|
-
rubocop-ast (1.
|
79
|
-
parser (>= 3.
|
80
|
-
rubocop-config-umbrellio (1.
|
81
|
-
rubocop (
|
82
|
-
rubocop-performance (
|
83
|
-
rubocop-rails (
|
84
|
-
rubocop-rake (
|
85
|
-
rubocop-rspec (
|
86
|
-
rubocop-sequel (
|
87
|
-
rubocop-performance (1.
|
88
|
-
rubocop (>=
|
85
|
+
rubocop-ast (1.19.1)
|
86
|
+
parser (>= 3.1.1.0)
|
87
|
+
rubocop-config-umbrellio (1.30.0.65)
|
88
|
+
rubocop (~> 1.30.0)
|
89
|
+
rubocop-performance (~> 1.14.0)
|
90
|
+
rubocop-rails (~> 2.14.2)
|
91
|
+
rubocop-rake (~> 0.6.0)
|
92
|
+
rubocop-rspec (~> 2.11.1)
|
93
|
+
rubocop-sequel (~> 0.3.3)
|
94
|
+
rubocop-performance (1.14.3)
|
95
|
+
rubocop (>= 1.7.0, < 2.0)
|
89
96
|
rubocop-ast (>= 0.4.0)
|
90
|
-
rubocop-rails (2.
|
97
|
+
rubocop-rails (2.14.2)
|
91
98
|
activesupport (>= 4.2.0)
|
92
99
|
rack (>= 1.1)
|
93
|
-
rubocop (>=
|
94
|
-
rubocop-rake (0.
|
95
|
-
rubocop
|
96
|
-
rubocop-rspec (2.2.0)
|
100
|
+
rubocop (>= 1.7.0, < 2.0)
|
101
|
+
rubocop-rake (0.6.0)
|
97
102
|
rubocop (~> 1.0)
|
98
|
-
|
99
|
-
|
103
|
+
rubocop-rspec (2.11.1)
|
104
|
+
rubocop (~> 1.19)
|
105
|
+
rubocop-sequel (0.3.4)
|
100
106
|
rubocop (~> 1.0)
|
101
107
|
ruby-progressbar (1.11.0)
|
102
108
|
ruby2_keywords (0.0.5)
|
103
|
-
semantic_logger (4.
|
109
|
+
semantic_logger (4.11.0)
|
104
110
|
concurrent-ruby (~> 1.0)
|
105
|
-
sequel (5.
|
111
|
+
sequel (5.58.0)
|
106
112
|
simplecov (0.21.2)
|
107
113
|
docile (~> 1.1)
|
108
114
|
simplecov-html (~> 0.11)
|
109
115
|
simplecov_json_formatter (~> 0.1)
|
110
116
|
simplecov-html (0.12.3)
|
111
117
|
simplecov-lcov (0.8.0)
|
112
|
-
simplecov_json_formatter (0.1.
|
118
|
+
simplecov_json_formatter (0.1.4)
|
113
119
|
symbiont-ruby (0.7.0)
|
114
|
-
thor (1.1
|
115
|
-
|
120
|
+
thor (1.2.1)
|
121
|
+
timecop (0.9.5)
|
122
|
+
tzinfo (2.0.5)
|
116
123
|
concurrent-ruby (~> 1.0)
|
117
|
-
umbrellio-sequel-plugins (0.
|
124
|
+
umbrellio-sequel-plugins (0.9.0.76)
|
118
125
|
sequel
|
119
126
|
symbiont-ruby
|
120
|
-
unicode-display_width (2.
|
121
|
-
|
122
|
-
|
127
|
+
unicode-display_width (2.2.0)
|
128
|
+
webrick (1.7.0)
|
129
|
+
yard (0.9.28)
|
130
|
+
webrick (~> 1.7.0)
|
123
131
|
|
124
132
|
PLATFORMS
|
133
|
+
arm64-darwin-20
|
134
|
+
arm64-darwin-21
|
135
|
+
ruby
|
125
136
|
x86_64-darwin-20
|
126
137
|
x86_64-linux
|
127
138
|
|
@@ -140,8 +151,9 @@ DEPENDENCIES
|
|
140
151
|
semantic_logger
|
141
152
|
simplecov
|
142
153
|
simplecov-lcov
|
154
|
+
timecop
|
143
155
|
umbrellio-utils!
|
144
156
|
yard
|
145
157
|
|
146
158
|
BUNDLED WITH
|
147
|
-
2.
|
159
|
+
2.3.19
|
@@ -6,6 +6,8 @@ module UmbrellioUtils
|
|
6
6
|
|
7
7
|
HandledConstaintError = Class.new(StandardError)
|
8
8
|
|
9
|
+
DEFAULT_SLEEP_INTERVAL = defined?(Rails) && Rails.env.production? ? 1 : 0
|
10
|
+
|
9
11
|
def handle_constraint_error(constraint_name, &block)
|
10
12
|
DB.transaction(savepoint: true, &block)
|
11
13
|
rescue Sequel::UniqueConstraintViolation => e
|
@@ -22,16 +24,16 @@ module UmbrellioUtils
|
|
22
24
|
end
|
23
25
|
|
24
26
|
def each_record(dataset, **options, &block)
|
25
|
-
primary_key = primary_key_from(options)
|
27
|
+
primary_key = primary_key_from(**options)
|
28
|
+
|
26
29
|
with_temp_table(dataset, **options) do |ids|
|
27
30
|
dataset.model.where(primary_key => ids).each(&block)
|
28
31
|
end
|
29
32
|
end
|
30
33
|
|
31
|
-
def with_temp_table(dataset, **options)
|
32
|
-
primary_key = primary_key_from(options)
|
33
|
-
|
34
|
-
do_sleep = options.fetch(:sleep, Rails.env.production?)
|
34
|
+
def with_temp_table(dataset, page_size: 1_000, sleep: nil, **options)
|
35
|
+
primary_key = primary_key_from(**options)
|
36
|
+
sleep_interval = sleep_interval_from(sleep)
|
35
37
|
|
36
38
|
temp_table_name = create_temp_table(dataset, primary_key: primary_key)
|
37
39
|
|
@@ -49,7 +51,7 @@ module UmbrellioUtils
|
|
49
51
|
|
50
52
|
break if pk_set.empty?
|
51
53
|
|
52
|
-
sleep(
|
54
|
+
sleep(sleep_interval) if sleep_interval.positive?
|
53
55
|
clear_lamian_logs!
|
54
56
|
end
|
55
57
|
ensure
|
@@ -67,7 +69,9 @@ module UmbrellioUtils
|
|
67
69
|
type = model.db_schema[primary_key][:db_type]
|
68
70
|
|
69
71
|
DB.drop_table?(temp_table_name)
|
70
|
-
DB.create_table(temp_table_name
|
72
|
+
DB.create_table(temp_table_name, unlogged: true) do
|
73
|
+
column primary_key, type, primary_key: true
|
74
|
+
end
|
71
75
|
|
72
76
|
insert_ds = dataset.select(Sequel[model.table_name][primary_key])
|
73
77
|
DB[temp_table_name].insert(insert_ds)
|
@@ -76,8 +80,19 @@ module UmbrellioUtils
|
|
76
80
|
|
77
81
|
private
|
78
82
|
|
79
|
-
def primary_key_from(options)
|
83
|
+
def primary_key_from(**options)
|
80
84
|
options.fetch(:primary_key, :id)
|
81
85
|
end
|
86
|
+
|
87
|
+
def sleep_inteval_from(sleep)
|
88
|
+
case sleep
|
89
|
+
when Numeric
|
90
|
+
sleep
|
91
|
+
when FalseClass
|
92
|
+
0
|
93
|
+
else
|
94
|
+
DEFAULT_SLEEP_INTERVAL
|
95
|
+
end
|
96
|
+
end
|
82
97
|
end
|
83
98
|
end
|
data/umbrellio_utils.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.description = "UmbrellioUtils is collection of utility classes and helpers"
|
13
13
|
spec.homepage = "https://github.com/umbrellio/utils"
|
14
14
|
spec.license = "MIT"
|
15
|
-
spec.required_ruby_version = Gem::Requirement.new(">= 2.
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
|
16
16
|
|
17
17
|
spec.metadata["homepage_uri"] = spec.homepage
|
18
18
|
spec.metadata["source_code_uri"] = "https://github.com/umbrellio/utils"
|
@@ -43,5 +43,6 @@ Gem::Specification.new do |spec|
|
|
43
43
|
spec.add_development_dependency "semantic_logger"
|
44
44
|
spec.add_development_dependency "simplecov"
|
45
45
|
spec.add_development_dependency "simplecov-lcov"
|
46
|
+
spec.add_development_dependency "timecop"
|
46
47
|
spec.add_development_dependency "yard"
|
47
48
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: umbrellio-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- JustAnotherDude
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: memery
|
@@ -220,6 +220,20 @@ dependencies:
|
|
220
220
|
- - ">="
|
221
221
|
- !ruby/object:Gem::Version
|
222
222
|
version: '0'
|
223
|
+
- !ruby/object:Gem::Dependency
|
224
|
+
name: timecop
|
225
|
+
requirement: !ruby/object:Gem::Requirement
|
226
|
+
requirements:
|
227
|
+
- - ">="
|
228
|
+
- !ruby/object:Gem::Version
|
229
|
+
version: '0'
|
230
|
+
type: :development
|
231
|
+
prerelease: false
|
232
|
+
version_requirements: !ruby/object:Gem::Requirement
|
233
|
+
requirements:
|
234
|
+
- - ">="
|
235
|
+
- !ruby/object:Gem::Version
|
236
|
+
version: '0'
|
223
237
|
- !ruby/object:Gem::Dependency
|
224
238
|
name: yard
|
225
239
|
requirement: !ruby/object:Gem::Requirement
|
@@ -288,14 +302,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
288
302
|
requirements:
|
289
303
|
- - ">="
|
290
304
|
- !ruby/object:Gem::Version
|
291
|
-
version: 2.
|
305
|
+
version: 2.7.0
|
292
306
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
293
307
|
requirements:
|
294
308
|
- - ">="
|
295
309
|
- !ruby/object:Gem::Version
|
296
310
|
version: '0'
|
297
311
|
requirements: []
|
298
|
-
rubygems_version: 3.
|
312
|
+
rubygems_version: 3.3.17
|
299
313
|
signing_key:
|
300
314
|
specification_version: 4
|
301
315
|
summary: A set of utilities that speed up development
|