heroku_queue_time_logger 0.0.1 → 0.0.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.
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/heroku_queue_time_logger/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Roberts, Marc"]
|
6
|
+
gem.email = ["marc@neutroncreations.com"]
|
7
|
+
gem.description = %q{heroku queue time logger}
|
8
|
+
gem.summary = %q{heroku queue time logger}
|
9
|
+
gem.homepage = "http://github.com/neutroncreations/heroku_queue_time_logger"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/.*_spec.rb})
|
14
|
+
gem.name = "heroku_queue_time_logger"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = HerokuQueueTimeLogger::VERSION
|
17
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module HerokuQueueTimeLogger
|
2
|
+
|
3
|
+
# https://gist.github.com/a-warner/f5db30857ed3423cea79
|
4
|
+
# combination of https://gist.github.com/daveyeu/4960893
|
5
|
+
# and https://gist.github.com/jasonrclark/d82a1ea7695daac0b9ee
|
6
|
+
class Middleware
|
7
|
+
DEFAULTS_OPTIONS = {
|
8
|
+
:perf_headers => true
|
9
|
+
}
|
10
|
+
|
11
|
+
def initialize app, options = {}
|
12
|
+
@options = DEFAULTS_OPTIONS.merge options
|
13
|
+
@app = app
|
14
|
+
end
|
15
|
+
|
16
|
+
def call env
|
17
|
+
now = Time.now.to_f
|
18
|
+
|
19
|
+
# Delete Heroku's queue time header because it's incorrect and useless
|
20
|
+
env.delete("HTTP_X_HEROKU_QUEUE_WAIT_TIME")
|
21
|
+
|
22
|
+
microseconds = (now * 1_000_000).to_i
|
23
|
+
env["HTTP_X_MIDDLEWARE_START"] = "t=#{microseconds}"
|
24
|
+
|
25
|
+
perf_headers = {}
|
26
|
+
if (request_start = env["HTTP_X_REQUEST_START"])
|
27
|
+
request_start_microseconds = request_start.gsub("t=", "").to_i * 1_000
|
28
|
+
queue_time_microseconds = [ microseconds - request_start_microseconds, 0 ].max
|
29
|
+
env["HTTP_X_QUEUE_TIME"] = "t=#{queue_time_microseconds}"
|
30
|
+
|
31
|
+
queue_time_milliseconds = (queue_time_microseconds / 1_000).to_i
|
32
|
+
perf_headers["X-Queue-Time"] = queue_time_milliseconds.to_s if @options[:perf_headers]
|
33
|
+
end
|
34
|
+
|
35
|
+
status, headers, body = @app.call(env)
|
36
|
+
|
37
|
+
[ status, headers.merge(perf_headers), body ]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: heroku_queue_time_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -20,6 +20,11 @@ extra_rdoc_files: []
|
|
20
20
|
files:
|
21
21
|
- .gitignore
|
22
22
|
- README.md
|
23
|
+
- heroku_queue_time_logger.gemspec
|
24
|
+
- lib/heroku_queue_time_logger.rb
|
25
|
+
- lib/heroku_queue_time_logger/middleware.rb
|
26
|
+
- lib/heroku_queue_time_logger/railtie.rb
|
27
|
+
- lib/heroku_queue_time_logger/version.rb
|
23
28
|
homepage: http://github.com/neutroncreations/heroku_queue_time_logger
|
24
29
|
licenses: []
|
25
30
|
post_install_message:
|