unity-utils 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 +7 -0
- data/lib/unity/modules/cli_modeable.rb +26 -0
- data/lib/unity/modules/loggable.rb +31 -0
- data/lib/unity/utils/retrier.rb +41 -0
- data/lib/unity/utils/thread_pool.rb +34 -0
- data/lib/unity/utils.rb +9 -0
- data/lib/unity-utils.rb +3 -0
- metadata +64 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0e6f79e08835172b8e3c97077784c0da007f799121144b373a558095974bf939
|
4
|
+
data.tar.gz: 3c14790bf4729fcdbe7b595c70901b9ec4781bb6d758e61dd3b5c8edd92c9a41
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 99636ede0b5a432c4d3ee765372b21b281a99ae99afcf875c412eefbf0b6b0a7483996359c6abe113e368bb8082138eb6e69c659ad49d3d63dc5404bf3adcc6d
|
7
|
+
data.tar.gz: 595ed916892639af8ad913586f470a36ed5ea182d55b825af8e75f2296acd1e090902f6ea84d877c251c29ad44a25755063d2a24187a0037f3de28df2d5c160a
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ruby-progressbar'
|
4
|
+
|
5
|
+
module Unity
|
6
|
+
module Modules
|
7
|
+
module CliModeable
|
8
|
+
private
|
9
|
+
|
10
|
+
def cli_mode?
|
11
|
+
@cli_mode == true
|
12
|
+
end
|
13
|
+
|
14
|
+
def init_progressbar(amount, title = self.class.to_s)
|
15
|
+
return unless cli_mode?
|
16
|
+
|
17
|
+
@progressbar = ProgressBar.create(title: title, format: '%t, %c/%C,%e: |%B|')
|
18
|
+
@progressbar.total = amount
|
19
|
+
end
|
20
|
+
|
21
|
+
def incr_progressbar
|
22
|
+
@progressbar.increment if cli_mode?
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'logger'
|
4
|
+
|
5
|
+
module Unity
|
6
|
+
module Modules
|
7
|
+
module Logable
|
8
|
+
attr_reader :log_file, :logger
|
9
|
+
|
10
|
+
def clean_logfile
|
11
|
+
return if log_file.kind_of?(IO)
|
12
|
+
|
13
|
+
File.open(log_file, 'w') {}
|
14
|
+
end
|
15
|
+
|
16
|
+
def puts_log_path
|
17
|
+
$stdout.puts("All logs in #{log_file}")
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def exception_to_array(exception)
|
23
|
+
[
|
24
|
+
"exception=#{exception.class}",
|
25
|
+
"msg='#{exception.message}'",
|
26
|
+
"backtrace='#{exception.backtrace.first(4).join('; ')}'"
|
27
|
+
]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Unity
|
4
|
+
module Utils
|
5
|
+
class Retrier
|
6
|
+
attr_reader :errors, :max_retries, :sleep_factor
|
7
|
+
|
8
|
+
def self.call
|
9
|
+
new.call(&Proc.new) if block_given?
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(errors = nil, max_retries = 5, sleep_factor = 0.3)
|
13
|
+
@errors = errors || [StandardError]
|
14
|
+
@max_retries = max_retries
|
15
|
+
@sleep_factor = sleep_factor
|
16
|
+
end
|
17
|
+
|
18
|
+
def call
|
19
|
+
return unless block_given?
|
20
|
+
|
21
|
+
retries = 0
|
22
|
+
|
23
|
+
begin
|
24
|
+
yield
|
25
|
+
rescue *errors => e
|
26
|
+
retries += 1
|
27
|
+
raise e if retries > max_retries
|
28
|
+
|
29
|
+
sleep_on(retries)
|
30
|
+
retry
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def sleep_on(retries)
|
37
|
+
sleep((2**retries) * sleep_factor)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Unity
|
4
|
+
module Utils
|
5
|
+
class ThreadPool
|
6
|
+
def initialize(size)
|
7
|
+
@size = size
|
8
|
+
@jobs = Queue.new
|
9
|
+
@pool = Array.new(@size) do |i|
|
10
|
+
Thread.new do
|
11
|
+
Thread.current[:id] = i
|
12
|
+
catch(:exit) do
|
13
|
+
loop do
|
14
|
+
job, args = @jobs.pop
|
15
|
+
job.call(*args)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def schedule(*args, &block)
|
23
|
+
@jobs << [block, args]
|
24
|
+
end
|
25
|
+
|
26
|
+
def run!
|
27
|
+
@size.times do
|
28
|
+
schedule { throw :exit }
|
29
|
+
end
|
30
|
+
@pool.map(&:join)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/unity/utils.rb
ADDED
data/lib/unity-utils.rb
ADDED
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: unity-utils
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mikhail Georgievskiy
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-09-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ruby-progressbar
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description:
|
28
|
+
email:
|
29
|
+
- m.georgievskiy@rambler-co.ru
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- lib/unity-utils.rb
|
35
|
+
- lib/unity/modules/cli_modeable.rb
|
36
|
+
- lib/unity/modules/loggable.rb
|
37
|
+
- lib/unity/utils.rb
|
38
|
+
- lib/unity/utils/retrier.rb
|
39
|
+
- lib/unity/utils/thread_pool.rb
|
40
|
+
homepage: https://github.com/rambler-digital-solutions/unity-utils.git
|
41
|
+
licenses:
|
42
|
+
- MIT
|
43
|
+
metadata:
|
44
|
+
homepage_uri: https://github.com/rambler-digital-solutions/unity-utils.git
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
requirements: []
|
60
|
+
rubygems_version: 3.0.9
|
61
|
+
signing_key:
|
62
|
+
specification_version: 4
|
63
|
+
summary: Gem with useful utils for writing scripts on ruby
|
64
|
+
test_files: []
|