hirefire-resource 0.4.2 → 0.5.0

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
- SHA1:
3
- metadata.gz: e74599dff2d7b0509fc068e143312336e854e3c2
4
- data.tar.gz: d515af29724dbaff66c7f3fb24fd73c22a83c4c5
2
+ SHA256:
3
+ metadata.gz: 33c33c7654d2bec9a8f5a0325c508fcf1314555f1409f693808189057558a71f
4
+ data.tar.gz: dc51a264bac728b99397178bbf741d7b61589d57d9cdf6fb40ade130bdf51b22
5
5
  SHA512:
6
- metadata.gz: 9d43c787528213ec9956e16a804f407c106db4eba0f6f2c38d3f27626f8e81e7cd2b6d0f2419d3fd93d658736a80f275c6d71a046328b2429c79f603b0a96966
7
- data.tar.gz: 83fa2527ebf43e28fb7b6939f595c8c8715922404601ce1de488acd6534301e41f40038253e6d4935e94c1d1940c6247351dc61e3376bd09d2d95ca0696b29c2
6
+ metadata.gz: 10103ce68c4fb42249f533cc89b824a8ec200c4fb04ebfb059f3949cae0b7dda53eb2005d8c763dab431619be794fd9307847d4b57909c16d8bf0ba775378cb3
7
+ data.tar.gz: edaee01b36999e985f8f2858f81c99f89d119705b0e4a840190bb2d70cd282b4d86874501373992aabee7ca02534949fb6fa193cde119c5151d1d8b047a5b720
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- ## [HireFire](http://hirefire.io/) - Autoscaling for your Heroku dynos
1
+ ## [HireFire](https://www.hirefire.io/) - Autoscaling for your Heroku dynos
2
2
 
3
- Load-based scaling, schedule-based scaling, dyno crash recovery, for [Heroku](http://heroku.com/) web- and worker dynos.
3
+ Load-based scaling, schedule-based scaling, dyno crash recovery, for [Heroku](https://www.heroku.com/) web- and worker dynos.
4
4
 
5
5
  ---
6
6
 
@@ -27,7 +27,7 @@ It supports practically any Rack-based application or framework, such as:
27
27
  We provide convenient macros for the above mentioned worker libraries to calculate the queue size for each of them.
28
28
  If you wish to conribute more macros for other existing worker libraries feel free to send us a pull request.
29
29
 
30
- Here is an example with Ruby on Rails 3.
30
+ Here is an example with Rails 3+
31
31
 
32
32
  First, add the gem to your `Gemfile`:
33
33
 
@@ -83,7 +83,7 @@ dj_worker: QUEUES=encode,compress bundle exec rake jobs:work
83
83
 
84
84
  Now that HireFire will scale both of the these dyno types based on their individual queue sizes. To customize how they scale, log in to the HireFire web interface.
85
85
 
86
- Visit the [official website](http://www.hirefire.io/) for more information!
86
+ Visit the [official website](https://www.hirefire.io/) for more information!
87
87
 
88
88
  ### License
89
89
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = "hirefire-resource"
5
- gem.version = "0.4.2"
5
+ gem.version = "0.5.0"
6
6
  gem.platform = Gem::Platform::RUBY
7
7
  gem.authors = "Michael van Rooijen"
8
8
  gem.email = "michael@hirefire.io"
@@ -33,6 +33,8 @@ module HireFire
33
33
  def call(env)
34
34
  @env = env
35
35
 
36
+ handle_queue(env["HTTP_X_REQUEST_START"])
37
+
36
38
  if test?
37
39
  [ 200, TEST_HEADERS, self ]
38
40
  elsif info?
@@ -66,14 +68,17 @@ module HireFire
66
68
  #
67
69
  def dynos
68
70
  dyno_data = HireFire::Resource.dynos.inject(String.new) do |json, dyno|
69
- json << %|,{"name":"#{dyno[:name]}","quantity":#{dyno[:quantity].call || "null"}}|; json
71
+ json << %(,{"name":"#{dyno[:name]}","quantity":#{dyno[:quantity].call || "null"}})
72
+ json
70
73
  end
71
74
 
72
75
  "[#{dyno_data.sub(",","")}]"
73
76
  end
74
77
 
75
-
76
78
  # Rack PATH_INFO with any RAILS_RELATIVE_URL_ROOT stripped off
79
+ #
80
+ # @return [String]
81
+ #
77
82
  def path
78
83
  if @path_prefix
79
84
  @env["PATH_INFO"].gsub(@path_prefix, "")
@@ -97,5 +102,31 @@ module HireFire
97
102
  def info?
98
103
  path == "/hirefire/#{@token || "development"}/info"
99
104
  end
105
+
106
+ # Writes the Heroku Router queue time to STDOUT if a String was provided.
107
+ #
108
+ # @param [String] the timestamp from HTTP_X_REQUEST_START.
109
+ #
110
+ def handle_queue(value)
111
+ log_queue(value) if value
112
+ end
113
+
114
+ # Writes the Heroku Router queue time to STDOUT.
115
+ #
116
+ # @param [String] the timestamp from HTTP_X_REQUEST_START.
117
+ #
118
+ def log_queue(value)
119
+ STDOUT.puts("[hirefire:router] queue=#{get_queue(value)}ms")
120
+ end
121
+
122
+ # Calculates the difference, in milliseconds, between the
123
+ # HTTP_X_REQUEST_START time and the current time.
124
+ #
125
+ # @param [String] the timestamp from HTTP_X_REQUEST_START.
126
+ # @return [Integer] the queue time in milliseconds.
127
+ #
128
+ def get_queue(value)
129
+ (Time.now.to_f * 1000).to_i - value.to_i
130
+ end
100
131
  end
101
132
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hirefire-resource
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael van Rooijen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-02 00:00:00.000000000 Z
11
+ date: 2018-05-04 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Load- and schedule-based scaling for web- and worker dynos
14
14
  email: michael@hirefire.io
@@ -57,7 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
57
57
  version: '0'
58
58
  requirements: []
59
59
  rubyforge_project:
60
- rubygems_version: 2.6.8
60
+ rubygems_version: 2.7.6
61
61
  signing_key:
62
62
  specification_version: 4
63
63
  summary: Autoscaling for your Heroku dynos