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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0784b080a70e7097113e64f9f217d463ebc35920cb5938c8543423321c1ea0ed'
4
- data.tar.gz: 451b025d9d3283946d8bc791ab085903b516bc8aeadbdac7cd38076ca59afc16
3
+ metadata.gz: 1d67a648a7193b2ca7c50d5d15963e41b954984b1f4f9f451cc0fdaf16f4bd7a
4
+ data.tar.gz: 50d01f6b7de34df8e0ad94cae1e3a22df9b07a3bc36e9a0fe0dd5eeed9d737d1
5
5
  SHA512:
6
- metadata.gz: b51c443ac3ea961f24d79c9cb6a0039d5e00e50a8e7349509adab7091b2c789dc51f01c1bbbd2c41b83a24c1ac2d18da7215ae25b6c4878aad461e18ada50193
7
- data.tar.gz: a1f2193a51c33ace2672b0dfa8534bb34402c2e9091c7fdbc58cbbf9ff87466ffc228b60513bd0cce75f7b148de0c1cd93b90dbec9d25d253f0554e40a814f9d
6
+ metadata.gz: f2d740e9c833e92682dc88265853d5107f4757f549aedeb444704c1f162b90b1dae168e6d89e31a36e2ef87dfd945246c1a57de5a0aee7f2d6e0bd6fb9507b85
7
+ data.tar.gz: ca4ed220c992b89ca53e28a01ab766a1142ce984c3324631d51194673ea0153a67f848fd7a155aa23b917edc29a8a8514a21cd5c73ea21d0932f198819083c8e
@@ -27,6 +27,7 @@ jobs:
27
27
  ${{ runner.os }}-${{ matrix.ruby }}-gems-
28
28
  - name: Setup gems
29
29
  run: |
30
+ gem install bundler
30
31
  bundle config path vendor/bundle
31
32
  bundle install --jobs 4
32
33
  - name: Rubocop
@@ -1,5 +1,9 @@
1
1
  inherit_gem:
2
2
  rubocop-discourse: default.yml
3
+
3
4
  inherit_mode:
4
5
  merge:
5
6
  - Exclude
7
+
8
+ RSpec/MessageSpies:
9
+ EnforcedStyle: receive
@@ -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.formatter = ->(s, t, p, m) do
80
- th_n = if Thread.current.name
81
- #:nocov:
82
- Thread.current.name
83
- #:nocov:
84
- else
85
- thread_map_mutex.synchronize do
86
- Thread.current[:thread_map_number] ||= begin
87
- Thread.list.select { |th| th[:thread_map_number] }.length
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
- ts = log_enable_timestamps ? "#{t.utc.strftime("%FT%T.%NZ")} " : ""
93
- "#{ts}#{$$}##{th_n} #{s[0]} [#{p}] #{m}\n"
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.logger.info(config.service_name) { "Starting metrics server on port #{config.metrics_port}" }
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.logger.info(config.service_name) { "Configuring loggerstash to send to #{config.logstash_server}" }
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
- logger.info(logloc) { "Starting service #{@config.service_name}" }
37
- logger.info(logloc) { (["Environment:"] + @config.env.map { |k, v| "#{k}=#{v.inspect}" }).join("\n ") }
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.2
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: 2020-12-09 00:00:00.000000000 Z
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: []