upfluence-utils 0.11.0 → 0.11.2
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/lib/upfluence/peer.rb +107 -9
- data/lib/upfluence/utils/interval_executor.rb +19 -0
- data/lib/upfluence/utils/version.rb +1 -1
- data/lib/upfluence/utils.rb +1 -0
- metadata +8 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: '009492a484b02ac991425525ba56a1277ca944eb088950858ebbcf7bd3f062ad'
|
|
4
|
+
data.tar.gz: e514f0846584054a728575335a7d3658417ae419975482aeffbe87204044c7a6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 16caf3863aa6bf859c1110ecb8296f9b7e4b494bb13e4a506c1f7e4fd3894934d0ef242c933c108aa6ca4f1fae7377211cab965da5ff15ddd685062394f5ea70
|
|
7
|
+
data.tar.gz: 455dc4eeba184d66017cb8d805c257544cd68a63f5679f3140bebbdd7850dc5cb559ad2138e62181db7bca431dc15e4651682f85580d478e0322691b6d7d1e2a
|
data/lib/upfluence/peer.rb
CHANGED
|
@@ -1,28 +1,126 @@
|
|
|
1
|
+
require 'cgi'
|
|
2
|
+
|
|
1
3
|
module Upfluence
|
|
2
4
|
class Peer
|
|
5
|
+
class Version
|
|
6
|
+
class SemanticVersion
|
|
7
|
+
attr_reader :major, :minor, :patch, :suffix
|
|
8
|
+
|
|
9
|
+
def initialize(major:, minor:, patch:, suffix: nil)
|
|
10
|
+
@major = major
|
|
11
|
+
@minor = minor
|
|
12
|
+
@patch = patch
|
|
13
|
+
@suffix = suffix
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def to_s
|
|
17
|
+
v = "v#{@major}.#{@minor}.#{@patch}"
|
|
18
|
+
|
|
19
|
+
v += "-#{@suffix}" if @suffix
|
|
20
|
+
v
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
class << self
|
|
24
|
+
def parse(version)
|
|
25
|
+
return nil unless version
|
|
26
|
+
|
|
27
|
+
v, suffix = version.split('-', 2)
|
|
28
|
+
|
|
29
|
+
vs = v.split('.')
|
|
30
|
+
|
|
31
|
+
return nil unless vs.count.eql? 3
|
|
32
|
+
|
|
33
|
+
SemanticVersion.new(
|
|
34
|
+
major: vs[0].delete_prefix('v').to_i,
|
|
35
|
+
minor: vs[1].to_i,
|
|
36
|
+
patch: vs[2].to_i,
|
|
37
|
+
suffix: suffix
|
|
38
|
+
)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
class GitVersion
|
|
44
|
+
attr_reader :commit, :remote, :branch
|
|
45
|
+
|
|
46
|
+
def initialize(commit:, remote: nil, branch: nil)
|
|
47
|
+
@commit = commit
|
|
48
|
+
@remote = remote
|
|
49
|
+
@branch = branch
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def to_s
|
|
53
|
+
"v0.0.0+git-#{@commit[0..6]}"
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
DEFAULT_VERSION = 'v0.0.0-dirty'.freeze
|
|
58
|
+
|
|
59
|
+
attr_reader :git, :semantic
|
|
60
|
+
|
|
61
|
+
def initialize(git, semantic)
|
|
62
|
+
@git = git
|
|
63
|
+
@semantic = semantic
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def to_s
|
|
67
|
+
return @semantic.to_s if @semantic
|
|
68
|
+
return @git.to_s if @git
|
|
69
|
+
|
|
70
|
+
DEFAULT_VERSION
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
3
74
|
attr_reader :environment, :authority, :instance_name, :project_name,
|
|
4
75
|
:app_name
|
|
5
76
|
|
|
6
|
-
def initialize(
|
|
7
|
-
|
|
8
|
-
@
|
|
9
|
-
@
|
|
10
|
-
@
|
|
11
|
-
@
|
|
77
|
+
def initialize(authority:, instance_name:, app_name:, project_name:,
|
|
78
|
+
environment:, version: nil)
|
|
79
|
+
@authority = authority || 'local'
|
|
80
|
+
@instance_name = instance_name || 'unknown-server'
|
|
81
|
+
@app_name = app_name || 'unknown-app'
|
|
82
|
+
@project_name = project_name || 'unknown-app'
|
|
83
|
+
@environment = environment || 'development'
|
|
84
|
+
@version = version
|
|
12
85
|
end
|
|
13
86
|
|
|
14
87
|
def to_url
|
|
15
|
-
|
|
88
|
+
query = {
|
|
89
|
+
'app-name' => @app_name,
|
|
90
|
+
'project-name' => @project_name,
|
|
91
|
+
'git-version' => @version.git&.commit,
|
|
92
|
+
'semantic-version' => @version.semantic&.to_s
|
|
93
|
+
}.compact.map { |k, v| "#{k}=#{CGI.escape(v)}" }.join('&')
|
|
94
|
+
|
|
95
|
+
"peer://#{@environment}@#{@authority}/#{@instance_name}?#{query}"
|
|
16
96
|
end
|
|
17
97
|
|
|
18
98
|
class << self
|
|
19
99
|
def from_env
|
|
20
100
|
Peer.new(
|
|
21
101
|
authority: ENV['AUTHORITY'],
|
|
22
|
-
instance_name: ENV['
|
|
102
|
+
instance_name: ENV['UNIT_NAME'],
|
|
23
103
|
app_name: ENV['APP_NAME'],
|
|
24
104
|
project_name: ENV['PROJECT_NAME'],
|
|
25
|
-
environment: ENV['ENV']
|
|
105
|
+
environment: ENV['ENV'],
|
|
106
|
+
version: Version.new(
|
|
107
|
+
build_git_version,
|
|
108
|
+
Version::SemanticVersion.parse(ENV['VERSION'])
|
|
109
|
+
)
|
|
110
|
+
)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
private
|
|
114
|
+
|
|
115
|
+
def build_git_version
|
|
116
|
+
commit = ENV['GIT_COMMIT']
|
|
117
|
+
|
|
118
|
+
return nil unless commit
|
|
119
|
+
|
|
120
|
+
Version::GitVersion.new(
|
|
121
|
+
commit: commit,
|
|
122
|
+
remote: ENV['GIT_REMOTE'],
|
|
123
|
+
branch: ENV['GIT_BRANCH']
|
|
26
124
|
)
|
|
27
125
|
end
|
|
28
126
|
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Upfluence
|
|
2
|
+
module Utils
|
|
3
|
+
class IntervalExecutor
|
|
4
|
+
DEFAULT_INTERVAL = 60*60*6
|
|
5
|
+
|
|
6
|
+
class << self
|
|
7
|
+
def start(interval = DEFAULT_INTERVAL)
|
|
8
|
+
Thread.new do
|
|
9
|
+
loop do
|
|
10
|
+
yield
|
|
11
|
+
|
|
12
|
+
sleep(interval)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
data/lib/upfluence/utils.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: upfluence-utils
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.11.
|
|
4
|
+
version: 0.11.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Upfluence
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2022-09-16 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -234,7 +234,7 @@ dependencies:
|
|
|
234
234
|
- - ">="
|
|
235
235
|
- !ruby/object:Gem::Version
|
|
236
236
|
version: '0'
|
|
237
|
-
description:
|
|
237
|
+
description:
|
|
238
238
|
email:
|
|
239
239
|
- dev@upfluence.com
|
|
240
240
|
executables: []
|
|
@@ -278,6 +278,7 @@ files:
|
|
|
278
278
|
- lib/upfluence/resources/countries.rb
|
|
279
279
|
- lib/upfluence/utils.rb
|
|
280
280
|
- lib/upfluence/utils/http/middleware/null.rb
|
|
281
|
+
- lib/upfluence/utils/interval_executor.rb
|
|
281
282
|
- lib/upfluence/utils/semaphore.rb
|
|
282
283
|
- lib/upfluence/utils/thrift.rb
|
|
283
284
|
- lib/upfluence/utils/thrift/middleware.rb
|
|
@@ -292,7 +293,7 @@ homepage: https://github.com/upfluence/rbutils
|
|
|
292
293
|
licenses:
|
|
293
294
|
- MIT
|
|
294
295
|
metadata: {}
|
|
295
|
-
post_install_message:
|
|
296
|
+
post_install_message:
|
|
296
297
|
rdoc_options: []
|
|
297
298
|
require_paths:
|
|
298
299
|
- lib
|
|
@@ -307,8 +308,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
307
308
|
- !ruby/object:Gem::Version
|
|
308
309
|
version: '0'
|
|
309
310
|
requirements: []
|
|
310
|
-
rubygems_version: 3.1.
|
|
311
|
-
signing_key:
|
|
311
|
+
rubygems_version: 3.1.2
|
|
312
|
+
signing_key:
|
|
312
313
|
specification_version: 4
|
|
313
314
|
summary: Upfluence common utils for Ruby projects
|
|
314
315
|
test_files: []
|