service_skeleton 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +1 -0
- data/.rubocop.yml +4 -0
- data/lib/service_skeleton/config.rb +20 -13
- data/lib/service_skeleton/generator.rb +2 -2
- data/lib/service_skeleton/runner.rb +2 -2
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d67a648a7193b2ca7c50d5d15963e41b954984b1f4f9f451cc0fdaf16f4bd7a
|
4
|
+
data.tar.gz: 50d01f6b7de34df8e0ad94cae1e3a22df9b07a3bc36e9a0fe0dd5eeed9d737d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2d740e9c833e92682dc88265853d5107f4757f549aedeb444704c1f162b90b1dae168e6d89e31a36e2ef87dfd945246c1a57de5a0aee7f2d6e0bd6fb9507b85
|
7
|
+
data.tar.gz: ca4ed220c992b89ca53e28a01ab766a1142ce984c3324631d51194673ea0153a67f848fd7a155aa23b917edc29a8a8514a21cd5c73ea21d0932f198819083c8e
|
data/.github/workflows/ci.yml
CHANGED
data/.rubocop.yml
CHANGED
@@ -8,7 +8,7 @@ require "loggerstash"
|
|
8
8
|
|
9
9
|
module ServiceSkeleton
|
10
10
|
class Config
|
11
|
-
attr_reader :logger, :env, :service_name
|
11
|
+
attr_reader :logger, :pre_run_logger, :env, :service_name
|
12
12
|
|
13
13
|
def initialize(env, service_name, variables)
|
14
14
|
@service_name = service_name
|
@@ -66,6 +66,11 @@ module ServiceSkeleton
|
|
66
66
|
|
67
67
|
@logger = Logger.new(log_file || $stderr, shift_age, shift_size)
|
68
68
|
|
69
|
+
# Can be used prior to a call to ultravisor#run. This prevents a race condition
|
70
|
+
# when a logstash server is configured but the logstash writer is not yet
|
71
|
+
# initialised. This should never be updated after it is configured.
|
72
|
+
@pre_run_logger = Logger.new(log_file || $stderr, shift_age, shift_size)
|
73
|
+
|
69
74
|
if Thread.main
|
70
75
|
Thread.main[:thread_map_number] = 0
|
71
76
|
else
|
@@ -76,21 +81,23 @@ module ServiceSkeleton
|
|
76
81
|
|
77
82
|
thread_map_mutex = Mutex.new
|
78
83
|
|
79
|
-
@logger
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
Thread.
|
84
|
+
[@logger, @pre_run_logger].each do |logger|
|
85
|
+
logger.formatter = ->(s, t, p, m) do
|
86
|
+
th_n = if Thread.current.name
|
87
|
+
#:nocov:
|
88
|
+
Thread.current.name
|
89
|
+
#:nocov:
|
90
|
+
else
|
91
|
+
thread_map_mutex.synchronize do
|
92
|
+
Thread.current[:thread_map_number] ||= begin
|
93
|
+
Thread.list.select { |th| th[:thread_map_number] }.length
|
94
|
+
end
|
88
95
|
end
|
89
96
|
end
|
90
|
-
end
|
91
97
|
|
92
|
-
|
93
|
-
|
98
|
+
ts = log_enable_timestamps ? "#{t.utc.strftime("%FT%T.%NZ")} " : ""
|
99
|
+
"#{ts}#{$$}##{th_n} #{s[0]} [#{p}] #{m}\n"
|
100
|
+
end
|
94
101
|
end
|
95
102
|
|
96
103
|
@logger.filters = []
|
@@ -45,7 +45,7 @@ module ServiceSkeleton
|
|
45
45
|
end
|
46
46
|
|
47
47
|
if config.metrics_port
|
48
|
-
config.
|
48
|
+
config.pre_run_logger.info(config.service_name) { "Starting metrics server on port #{config.metrics_port}" }
|
49
49
|
ultravisor.add_child(
|
50
50
|
id: :metrics_server,
|
51
51
|
klass: Frankenstein::Server,
|
@@ -62,7 +62,7 @@ module ServiceSkeleton
|
|
62
62
|
|
63
63
|
def initialize_loggerstash(ultravisor, config, registry)
|
64
64
|
if config.logstash_server && !config.logstash_server.empty?
|
65
|
-
config.
|
65
|
+
config.pre_run_logger.info(config.service_name) { "Configuring loggerstash to send to #{config.logstash_server}" }
|
66
66
|
|
67
67
|
ultravisor.add_child(
|
68
68
|
id: :logstash_writer,
|
@@ -33,8 +33,8 @@ module ServiceSkeleton
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def run
|
36
|
-
|
37
|
-
|
36
|
+
@config.pre_run_logger.info(logloc) { "Starting service #{@config.service_name}" }
|
37
|
+
@config.pre_run_logger.info(logloc) { (["Environment:"] + @config.env.map { |k, v| "#{k}=#{v.inspect}" }).join("\n ") }
|
38
38
|
|
39
39
|
@ultravisor.run
|
40
40
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: service_skeleton
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Palmer
|
8
8
|
- Sam Saffron
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2021-01-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: frankenstein
|
@@ -335,7 +335,7 @@ files:
|
|
335
335
|
homepage: https://github.com/discourse/service_skeleton
|
336
336
|
licenses: []
|
337
337
|
metadata: {}
|
338
|
-
post_install_message:
|
338
|
+
post_install_message:
|
339
339
|
rdoc_options: []
|
340
340
|
require_paths:
|
341
341
|
- lib
|
@@ -351,7 +351,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
351
351
|
version: '0'
|
352
352
|
requirements: []
|
353
353
|
rubygems_version: 3.1.4
|
354
|
-
signing_key:
|
354
|
+
signing_key:
|
355
355
|
specification_version: 4
|
356
356
|
summary: The bare bones of a service
|
357
357
|
test_files: []
|