roo_on_rails 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,75 +1,88 @@
1
1
  PATH
2
- remote: ../
2
+ remote: ..
3
3
  specs:
4
- roo_on_rails (1.1.0)
4
+ roo_on_rails (1.3.0)
5
5
  dotenv-rails (~> 2.1)
6
6
  hashie (~> 3.4)
7
+ hirefire-resource
7
8
  newrelic_rpm (~> 3.17)
9
+ octokit
8
10
  platform-api (~> 0.8)
9
11
  rack-ssl-enforcer
10
12
  rack-timeout
11
13
  rails (>= 3.2.22, < 5.1)
14
+ sidekiq
12
15
 
13
16
  GEM
14
17
  remote: https://rubygems.org/
15
18
  specs:
16
- actioncable (5.0.1)
17
- actionpack (= 5.0.1)
18
- nio4r (~> 1.2)
19
+ actioncable (5.0.2)
20
+ actionpack (= 5.0.2)
21
+ nio4r (>= 1.2, < 3.0)
19
22
  websocket-driver (~> 0.6.1)
20
- actionmailer (5.0.1)
21
- actionpack (= 5.0.1)
22
- actionview (= 5.0.1)
23
- activejob (= 5.0.1)
23
+ actionmailer (5.0.2)
24
+ actionpack (= 5.0.2)
25
+ actionview (= 5.0.2)
26
+ activejob (= 5.0.2)
24
27
  mail (~> 2.5, >= 2.5.4)
25
28
  rails-dom-testing (~> 2.0)
26
- actionpack (5.0.1)
27
- actionview (= 5.0.1)
28
- activesupport (= 5.0.1)
29
+ actionpack (5.0.2)
30
+ actionview (= 5.0.2)
31
+ activesupport (= 5.0.2)
29
32
  rack (~> 2.0)
30
33
  rack-test (~> 0.6.3)
31
34
  rails-dom-testing (~> 2.0)
32
35
  rails-html-sanitizer (~> 1.0, >= 1.0.2)
33
- actionview (5.0.1)
34
- activesupport (= 5.0.1)
36
+ actionview (5.0.2)
37
+ activesupport (= 5.0.2)
35
38
  builder (~> 3.1)
36
39
  erubis (~> 2.7.0)
37
40
  rails-dom-testing (~> 2.0)
38
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
39
- activejob (5.0.1)
40
- activesupport (= 5.0.1)
41
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
42
+ activejob (5.0.2)
43
+ activesupport (= 5.0.2)
41
44
  globalid (>= 0.3.6)
42
- activemodel (5.0.1)
43
- activesupport (= 5.0.1)
44
- activerecord (5.0.1)
45
- activemodel (= 5.0.1)
46
- activesupport (= 5.0.1)
45
+ activemodel (5.0.2)
46
+ activesupport (= 5.0.2)
47
+ activerecord (5.0.2)
48
+ activemodel (= 5.0.2)
49
+ activesupport (= 5.0.2)
47
50
  arel (~> 7.0)
48
- activesupport (5.0.1)
51
+ activesupport (5.0.2)
49
52
  concurrent-ruby (~> 1.0, >= 1.0.2)
50
53
  i18n (~> 0.7)
51
54
  minitest (~> 5.1)
52
55
  tzinfo (~> 1.1)
53
- appraisal (2.1.0)
56
+ addressable (2.5.1)
57
+ public_suffix (~> 2.0, >= 2.0.2)
58
+ appraisal (2.2.0)
54
59
  bundler
55
60
  rake
56
61
  thor (>= 0.14.0)
57
62
  arel (7.1.4)
58
63
  builder (3.2.3)
59
64
  byebug (9.0.6)
65
+ codecov (0.1.10)
66
+ json
67
+ simplecov
68
+ url
60
69
  coderay (1.1.1)
61
70
  concurrent-ruby (1.0.5)
71
+ connection_pool (2.2.1)
62
72
  diff-lcs (1.3)
73
+ docile (1.1.5)
63
74
  dotenv (2.2.0)
64
75
  dotenv-rails (2.2.0)
65
76
  dotenv (= 2.2.0)
66
77
  railties (>= 3.2, < 5.1)
67
78
  erubis (2.7.0)
68
79
  excon (0.55.0)
69
- ffi (1.9.17)
80
+ faraday (0.12.1)
81
+ multipart-post (>= 1.2, < 3)
82
+ ffi (1.9.18)
70
83
  formatador (0.2.5)
71
- globalid (0.3.7)
72
- activesupport (>= 4.1.0)
84
+ globalid (0.4.0)
85
+ activesupport (>= 4.2.0)
73
86
  guard (2.14.1)
74
87
  formatador (>= 0.2.4)
75
88
  listen (>= 2.7, < 4.0)
@@ -89,7 +102,9 @@ GEM
89
102
  erubis (~> 2.0)
90
103
  excon
91
104
  multi_json (>= 1.9.2)
105
+ hirefire-resource (0.4.0)
92
106
  i18n (0.8.1)
107
+ json (2.1.0)
93
108
  listen (3.1.5)
94
109
  rb-fsevent (~> 0.9, >= 0.9.4)
95
110
  rb-inotify (~> 0.9, >= 0.9.7)
@@ -99,6 +114,7 @@ GEM
99
114
  lumberjack (1.0.11)
100
115
  mail (2.6.4)
101
116
  mime-types (>= 1.16, < 4)
117
+ memfs (1.0.0)
102
118
  method_source (0.8.2)
103
119
  mime-types (3.1)
104
120
  mime-types-data (~> 3.2015)
@@ -106,14 +122,18 @@ GEM
106
122
  mini_portile2 (2.1.0)
107
123
  minitest (5.10.1)
108
124
  multi_json (1.12.1)
125
+ multipart-post (2.0.0)
109
126
  nenv (0.3.0)
110
127
  newrelic_rpm (3.18.1.330)
111
- nio4r (1.2.1)
112
- nokogiri (1.7.0.1)
128
+ nio4r (2.0.0)
129
+ nokogiri (1.7.1)
113
130
  mini_portile2 (~> 2.1.0)
114
131
  notiffany (0.1.1)
115
132
  nenv (~> 0.1)
116
133
  shellany (~> 0.0)
134
+ octokit (4.7.0)
135
+ sawyer (~> 0.8.0, >= 0.5.3)
136
+ pg (0.20.0)
117
137
  platform-api (0.8.0)
118
138
  heroics (~> 0.0.17)
119
139
  pry (0.10.4)
@@ -123,31 +143,34 @@ GEM
123
143
  pry-byebug (3.4.2)
124
144
  byebug (~> 9.0)
125
145
  pry (~> 0.10)
146
+ public_suffix (2.0.5)
126
147
  rack (2.0.1)
148
+ rack-protection (1.5.3)
149
+ rack
127
150
  rack-ssl-enforcer (0.2.9)
128
151
  rack-test (0.6.3)
129
152
  rack (>= 1.0)
130
153
  rack-timeout (0.4.2)
131
- rails (5.0.1)
132
- actioncable (= 5.0.1)
133
- actionmailer (= 5.0.1)
134
- actionpack (= 5.0.1)
135
- actionview (= 5.0.1)
136
- activejob (= 5.0.1)
137
- activemodel (= 5.0.1)
138
- activerecord (= 5.0.1)
139
- activesupport (= 5.0.1)
154
+ rails (5.0.2)
155
+ actioncable (= 5.0.2)
156
+ actionmailer (= 5.0.2)
157
+ actionpack (= 5.0.2)
158
+ actionview (= 5.0.2)
159
+ activejob (= 5.0.2)
160
+ activemodel (= 5.0.2)
161
+ activerecord (= 5.0.2)
162
+ activesupport (= 5.0.2)
140
163
  bundler (>= 1.3.0, < 2.0)
141
- railties (= 5.0.1)
164
+ railties (= 5.0.2)
142
165
  sprockets-rails (>= 2.0.0)
143
166
  rails-dom-testing (2.0.2)
144
167
  activesupport (>= 4.2.0, < 6.0)
145
168
  nokogiri (~> 1.6)
146
169
  rails-html-sanitizer (1.0.3)
147
170
  loofah (~> 2.0)
148
- railties (5.0.1)
149
- actionpack (= 5.0.1)
150
- activesupport (= 5.0.1)
171
+ railties (5.0.2)
172
+ actionpack (= 5.0.2)
173
+ activesupport (= 5.0.2)
151
174
  method_source
152
175
  rake (>= 0.8.7)
153
176
  thor (>= 0.18.1, < 2.0)
@@ -155,6 +178,7 @@ GEM
155
178
  rb-fsevent (0.9.8)
156
179
  rb-inotify (0.9.8)
157
180
  ffi (>= 0.5.0)
181
+ redis (3.3.3)
158
182
  rspec (3.5.0)
159
183
  rspec-core (~> 3.5.0)
160
184
  rspec-expectations (~> 3.5.0)
@@ -169,7 +193,20 @@ GEM
169
193
  rspec-support (~> 3.5.0)
170
194
  rspec-support (3.5.0)
171
195
  ruby_dep (1.5.0)
196
+ sawyer (0.8.1)
197
+ addressable (>= 2.3.5, < 2.6)
198
+ faraday (~> 0.8, < 1.0)
172
199
  shellany (0.0.1)
200
+ sidekiq (5.0.0)
201
+ concurrent-ruby (~> 1.0)
202
+ connection_pool (~> 2.2, >= 2.2.0)
203
+ rack-protection (>= 1.5.0)
204
+ redis (~> 3.3, >= 3.3.3)
205
+ simplecov (0.14.1)
206
+ docile (~> 1.1.0)
207
+ json (>= 1.8, < 3)
208
+ simplecov-html (~> 0.10.0)
209
+ simplecov-html (0.10.0)
173
210
  slop (3.6.0)
174
211
  sprockets (3.7.1)
175
212
  concurrent-ruby (~> 1.0)
@@ -178,10 +215,12 @@ GEM
178
215
  actionpack (>= 4.0)
179
216
  activesupport (>= 4.0)
180
217
  sprockets (>= 3.0.0)
218
+ sqlite3 (1.3.13)
181
219
  thor (0.19.4)
182
220
  thread_safe (0.3.6)
183
- tzinfo (1.2.2)
221
+ tzinfo (1.2.3)
184
222
  thread_safe (~> 0.1)
223
+ url (0.3.2)
185
224
  websocket-driver (0.6.5)
186
225
  websocket-extensions (>= 0.1.0)
187
226
  websocket-extensions (0.1.2)
@@ -192,13 +231,18 @@ PLATFORMS
192
231
  DEPENDENCIES
193
232
  appraisal
194
233
  bundler (~> 1.13)
234
+ codecov
195
235
  guard
196
236
  guard-rspec
237
+ memfs
238
+ pg
197
239
  pry-byebug
198
240
  rails (~> 5.0)
199
241
  rake (~> 10.0)
200
242
  roo_on_rails!
201
243
  rspec (~> 3.0)
244
+ simplecov
245
+ sqlite3
202
246
  thor (~> 0.19)
203
247
 
204
248
  BUNDLED WITH
@@ -2,12 +2,15 @@ require 'roo_on_rails/checks/env_specific'
2
2
  require 'roo_on_rails/checks/github/branch_protection'
3
3
  require 'roo_on_rails/checks/heroku/app_exists'
4
4
  require 'roo_on_rails/checks/heroku/preboot_enabled'
5
+ require 'roo_on_rails/checks/heroku/app_exists'
6
+ require 'roo_on_rails/checks/sidekiq/settings'
5
7
 
6
8
  module RooOnRails
7
9
  module Checks
8
10
  class Environment < EnvSpecific
9
11
  requires GitHub::BranchProtection
10
12
  requires Heroku::PrebootEnabled
13
+ requires Sidekiq::Settings
11
14
 
12
15
  def call
13
16
  # nothing to do
@@ -52,7 +52,7 @@ module RooOnRails
52
52
  end
53
53
 
54
54
  def ensure_coverage_status_check!(contexts)
55
- return if (contexts & coverage_contexts) == coverage_contexts
55
+ return if (contexts & coverage_contexts).sort == coverage_contexts.sort
56
56
  fail! 'no code coverage status checks'
57
57
  end
58
58
 
@@ -92,7 +92,7 @@ module RooOnRails
92
92
 
93
93
  def ci_context
94
94
  if Pathname.new('.travis.yml').exist? then 'continuous-integration/travis-ci'
95
- else 'ci/circle-ci'
95
+ else 'ci/circleci'
96
96
  end
97
97
  end
98
98
 
@@ -13,7 +13,10 @@ module RooOnRails
13
13
  def self.included(by)
14
14
  by.class_eval do
15
15
  extend Forwardable
16
- delegate %i[ask say set_color] => :'RooOnRails::Checks::Helpers::Receiver.instance'
16
+ delegate %i(say ask yes? no? create_file
17
+ add_file remove_file copy_file
18
+ template directory inside inject_into_file
19
+ append_to_file) => :'RooOnRails::Checks::Helpers::Receiver.instance'
17
20
  end
18
21
  end
19
22
 
@@ -23,5 +26,3 @@ module RooOnRails
23
26
  end
24
27
  end
25
28
  end
26
-
27
-
@@ -0,0 +1,20 @@
1
+ require 'roo_on_rails/checks/sidekiq/sidekiq'
2
+ require 'roo_on_rails/checks/base'
3
+ require 'thor'
4
+
5
+ module RooOnRails
6
+ module Checks
7
+ module Sidekiq
8
+ class Settings < Base
9
+ requires Sidekiq
10
+ def intro
11
+ 'Checking Sidekiq settings.yml...'
12
+ end
13
+
14
+ def call
15
+ fail! 'Custom Sidekiq settings found.' if File.exist?('config/sidekiq.yml')
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,37 @@
1
+ require 'roo_on_rails/checks/base'
2
+ require 'thor'
3
+
4
+ module RooOnRails
5
+ module Checks
6
+ module Sidekiq
7
+ class Sidekiq < Base
8
+ WORKER_PROCFILE_LINE = 'worker: bundle exec roo_on_rails sidekiq'.freeze
9
+
10
+ def intro
11
+ 'Checking Sidekiq Setup...'
12
+ end
13
+
14
+ def call
15
+ unless ENV.fetch('SIDEKIQ_ENABLED', 'true').to_s =~ /\A(YES|TRUE|ON|1)\Z/i
16
+ pass 'SIDEKIQ_ENABLED is set to false'
17
+ return
18
+ end
19
+ check_for_procfile
20
+ end
21
+
22
+ def fix
23
+ if File.exist?('Procfile')
24
+ append_to_file 'Procfile', "\n#{WORKER_PROCFILE_LINE}"
25
+ else
26
+ create_file 'Procfile', WORKER_PROCFILE_LINE
27
+ end
28
+ end
29
+
30
+ def check_for_procfile
31
+ return if File.exist?('Procfile') && File.read('Procfile').include?('worker')
32
+ fail! "No Procfile found with a 'worker' command"
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,106 @@
1
+ require 'active_support/core_ext/module/delegation'
2
+ require 'active_support/core_ext/object/blank'
3
+ require 'active_support/version'
4
+ require 'logger'
5
+ require 'roo_on_rails/logfmt'
6
+
7
+ module RooOnRails
8
+ # Wraps any standard logger to provide context, similar to `ActiveSupport::TaggedLogging`
9
+ # but with key/value pairs that are appended to the end of the text.
10
+ #
11
+ # logger = RooOnRails::ContextLogging.new(ActiveSupport::Logger.new($stdout))
12
+ # logger.with(a: 1, b: 2) { logger.info 'Stuff' } # Logs "Stuff a=1 b=2"
13
+ # logger.with(a: 1) { logger.with(b: 2) { logger.info('Stuff') } } # Logs "Stuff a=1 b=2"
14
+ #
15
+ # The above methods persist the context in thread local storage so it will be attached to
16
+ # any logs made within the scope of the block, even in called methods. However, if your
17
+ # context only applies to the current log then you can chain off the `with` method.
18
+ #
19
+ # logger.with(a: 1, b: 2).info('Stuff') # Logs "Stuff a=1 b=2"
20
+ # logger.with(a: 1) { logger.with(b: 2).info('Stuff') } # Logs "Stuff a=1 b=2"
21
+ #
22
+ # Hashes, arrays and any complex object that supports `#to_json` will be output in escaped
23
+ # JSON format so that it can be parsed out of the attribute values.
24
+ module ContextLogging
25
+ module Formatter
26
+ def call(severity, timestamp, progname, msg)
27
+ super(severity, timestamp, progname, "#{msg}#{context_text}")
28
+ end
29
+
30
+ def with(**context)
31
+ Thread.handle_interrupt(Exception => :never) do
32
+ current_context.push(context)
33
+ begin
34
+ Thread.handle_interrupt(Exception => :immediate) do
35
+ yield self
36
+ end
37
+ ensure
38
+ current_context.pop
39
+ end
40
+ end
41
+ end
42
+
43
+ def clear_context!
44
+ current_context.clear
45
+ end
46
+
47
+ private
48
+
49
+ def current_context
50
+ # We use our object ID here to avoid conflicting with other instances
51
+ thread_key = @logging_context_key ||= "roo_on_rails:logging_context:#{object_id}".freeze
52
+ Thread.current[thread_key] ||= []
53
+ end
54
+
55
+ def context_text
56
+ context = current_context
57
+ return nil if context.empty?
58
+
59
+ merged_context = context.each_with_object({}) { |ctx, acc| acc.merge!(ctx) }
60
+ ' ' + Logfmt.dump(merged_context)
61
+ end
62
+ end
63
+
64
+ class LoggerProxy
65
+ def initialize(logger, context)
66
+ @logger = logger
67
+ @context = context
68
+ end
69
+
70
+ %i[debug info warn error fatal unknown].each do |severity|
71
+ define_method severity do |message|
72
+ @logger.with(**@context) { @logger.public_send(severity, message) }
73
+ end
74
+ end
75
+ end
76
+
77
+ def self.new(logger)
78
+ # Ensure we set a default formatter so we aren't extending nil!
79
+ logger.formatter ||=
80
+ if ActiveSupport::VERSION::MAJOR >= 4
81
+ require 'active_support/logger'
82
+ ActiveSupport::Logger::SimpleFormatter.new
83
+ else
84
+ require 'active_support/core_ext/logger'
85
+ ::Logger::SimpleFormatter.new
86
+ end
87
+ logger.formatter.extend(Formatter)
88
+ logger.extend(self)
89
+ end
90
+
91
+ delegate :clear_context!, to: :formatter
92
+
93
+ def with(**context)
94
+ if block_given?
95
+ formatter.with(**context) { yield self }
96
+ else
97
+ LoggerProxy.new(self, context)
98
+ end
99
+ end
100
+
101
+ def flush
102
+ clear_context!
103
+ super if defined?(super)
104
+ end
105
+ end
106
+ end
@@ -9,3 +9,6 @@ NEW_RELIC_DEVELOPER_MODE=false
9
9
  NEW_RELIC_LICENSE_KEY=override-me
10
10
  RACK_SERVICE_TIMEOUT=10
11
11
  RACK_WAIT_TIMEOUT=30
12
+ SIDEKIQ_ENABLED=true
13
+ SIDEKIQ_THREADS=25
14
+ SIDEKIQ_DATABASE_REAPING_FREQUENCY=10
@@ -0,0 +1,9 @@
1
+ require 'dotenv'
2
+ module RooOnRails
3
+ class Environment
4
+ def self.load
5
+ Dotenv.load
6
+ Dotenv.load File.expand_path('../default.env', __FILE__)
7
+ end
8
+ end
9
+ end
@@ -1,6 +1,7 @@
1
1
  require 'thor'
2
2
  require 'hashie'
3
3
  require 'roo_on_rails/checks/environment'
4
+ require 'roo_on_rails/environment'
4
5
 
5
6
  module RooOnRails
6
7
  class Harness
@@ -0,0 +1,44 @@
1
+ require 'json'
2
+
3
+ module RooOnRails
4
+ # A generator for the logfmt log format.
5
+ #
6
+ # @see https://brandur.org/logfmt The original description of logfmt
7
+ # @see https://godoc.org/github.com/kr/logfmt The 'reference' parser
8
+ module Logfmt
9
+ class << self
10
+ SPACE = 0x20
11
+ QUOTE = 0x22
12
+ EQUALS = 0x3d
13
+
14
+ def dump(hash)
15
+ return nil if hash.nil? || hash.empty?
16
+
17
+ hash.map { |k, v| "#{k}=#{dump_value(v)}" }.join(' ')
18
+ end
19
+
20
+ private
21
+
22
+ def dump_value(v)
23
+ str = case v
24
+ when String then v
25
+ when Symbol then v.to_s
26
+ when Array, Hash then JSON.dump(v)
27
+ else v.respond_to?(:to_json) ? v.to_json : v.inspect
28
+ end
29
+ escape(str)
30
+ end
31
+
32
+ def escape(str)
33
+ return str if ident?(str)
34
+
35
+ escaped = str.gsub(/(["\\])/, '\\\\\1')
36
+ %("#{escaped}")
37
+ end
38
+
39
+ def ident?(str)
40
+ str.bytes.all? { |b| b > SPACE && b != EQUALS && b != QUOTE }
41
+ end
42
+ end
43
+ end
44
+ end
@@ -18,7 +18,7 @@ module RooOnRails
18
18
 
19
19
  def call(env)
20
20
  @app.call(env)
21
- rescue Rack::Timeout::Error, Rack::Timeout::RequestTimeoutException
21
+ rescue ::Rack::Timeout::Error, ::Rack::Timeout::RequestTimeoutException
22
22
  Rails.logger.warn('Clearing ActiveRecord connection cache due to timeout')
23
23
  ActiveRecord::Base.connection.clear_cache!
24
24
  raise
@@ -1,10 +1,10 @@
1
1
  $stderr.puts 'loading roo_on_rails railtie'
2
-
2
+ require 'roo_on_rails/environment'
3
3
  module RooOnRails
4
4
  class Railtie < Rails::Railtie
5
5
  initializer 'roo_on_rails.default_env' do
6
6
  $stderr.puts 'initializer roo_on_rails.default_env'
7
- Dotenv.load File.expand_path('../default.env', __FILE__)
7
+ RooOnRails::Environment.load
8
8
  end
9
9
 
10
10
  # initializer 'roo_on_rails.print_env' do
@@ -0,0 +1,18 @@
1
+ module RooOnRails
2
+ module Railties
3
+ class Database < Rails::Railtie
4
+ if ActiveRecord::VERSION::MAJOR >= 4
5
+ initializer 'roo_on_rails.database', after: 'active_record.initialize_database' do
6
+ $stderr.puts 'initializer roo_on_rails.database'
7
+
8
+ config = ActiveRecord::Base.configurations[Rails.env]
9
+ config['variables'] ||= {}
10
+ config['variables']['statement_timeout'] = ENV.fetch('DATABASE_STATEMENT_TIMEOUT', 200)
11
+ config['reaping_frequency'] = ENV['DATABASE_REAPING_FREQUENCY']
12
+
13
+ ActiveRecord::Base.establish_connection
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -28,10 +28,13 @@ module RooOnRails
28
28
  app.config.middleware.use ::Rack::Deflater
29
29
  end
30
30
 
31
- app.config.middleware.insert_before(
32
- ActionDispatch::Cookies,
33
- ::Rack::SslEnforcer
34
- )
31
+ # Don't use SslEnforcer in test environment as it breaks Capybara
32
+ unless Rails.env.test?
33
+ app.config.middleware.insert_before(
34
+ ActionDispatch::Cookies,
35
+ ::Rack::SslEnforcer
36
+ )
37
+ end
35
38
  end
36
39
  end
37
40
  end
@@ -0,0 +1,11 @@
1
+ module RooOnRails
2
+ module Railties
3
+ class RakeTasks < Rails::Railtie
4
+ rake_tasks do
5
+ $stderr.puts 'initializer roo_on_rails.rake_tasks'
6
+
7
+ Dir[File.join(__dir__, '..', 'tasks', '*.rake')].each { |f| load f }
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,42 @@
1
+ require 'sidekiq'
2
+ require 'roo_on_rails/sidekiq/settings'
3
+ require 'roo_on_rails/sidekiq/sla_metric'
4
+
5
+ module RooOnRails
6
+ module Railties
7
+ class Sidekiq < Rails::Railtie
8
+ initializer 'roo_on_rails.sidekiq' do |app|
9
+ require 'hirefire-resource'
10
+ $stderr.puts 'initializer roo_on_rails.sidekiq'
11
+ break unless ENV.fetch('SIDEKIQ_ENABLED', 'true').to_s =~ /\A(YES|TRUE|ON|1)\Z/i
12
+ config_sidekiq
13
+ config_hirefire(app)
14
+ end
15
+
16
+ def config_hirefire(app)
17
+ unless ENV['HIREFIRE_TOKEN']
18
+ warn 'No HIREFIRE_TOKEN token set, auto scaling not enabled'
19
+ return
20
+ end
21
+ add_middleware(app)
22
+ end
23
+
24
+ def config_sidekiq
25
+ ::Sidekiq.configure_server do |x|
26
+ x.options[:concurrency] = RooOnRails::Sidekiq::Settings.concurrency.to_i
27
+ x.options[:queues] = RooOnRails::Sidekiq::Settings.queues
28
+ end
29
+ end
30
+
31
+ def add_middleware(app)
32
+ $stderr.puts 'HIREFIRE_TOKEN set'
33
+ app.middleware.use HireFire::Middleware
34
+ HireFire::Resource.configure do |config|
35
+ config.dyno(:worker) do
36
+ RooOnRails::Sidekiq::SlaMetric.queue
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,13 @@
1
+ require 'roo_on_rails/environment'
2
+ module RooOnRails
3
+ module Sidekiq
4
+ class Loader
5
+ def self.run
6
+ RooOnRails::Environment.load
7
+ ENV['RAILS_MAX_THREADS'] = (ENV.fetch('SIDEKIQ_THREADS').to_i + 1).to_s
8
+ ENV['DATABASE_REAPING_FREQUENCY'] = ENV['SIDEKIQ_DATABASE_REAPING_FREQUENCY']
9
+ exec 'sidekiq'
10
+ end
11
+ end
12
+ end
13
+ end