hirefireapp 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.
- data/README.md +4 -3
- data/bin/hirefireapp +1 -1
- data/hirefireapp.gemspec +4 -4
- data/lib/hirefireapp/middleware.rb +29 -8
- metadata +4 -4
    
        data/README.md
    CHANGED
    
    | @@ -1,5 +1,6 @@ | |
| 1 | 
            -
            #  | 
| 1 | 
            +
            # HireFire - The Heroku Worker Manager
         | 
| 2 2 |  | 
| 3 | 
            -
             | 
| 3 | 
            +
            HireFire is a hosted service that scales your Heroku web and worker dynos when necessary.
         | 
| 4 | 
            +
            This allows you to save a lot of money by allowing HireFire to shut down idle workers, and add scalability to both your web as well as your worker dynos.
         | 
| 4 5 |  | 
| 5 | 
            -
            [ | 
| 6 | 
            +
            Visit the [official website](http://hirefireapp.com/) for more information!
         | 
    
        data/bin/hirefireapp
    CHANGED
    
    
    
        data/hirefireapp.gemspec
    CHANGED
    
    | @@ -4,17 +4,17 @@ Gem::Specification.new do |gem| | |
| 4 4 |  | 
| 5 5 | 
             
              # General configuration / information
         | 
| 6 6 | 
             
              gem.name        = 'hirefireapp'
         | 
| 7 | 
            -
              gem.version     = '0.0. | 
| 7 | 
            +
              gem.version     = '0.0.2'
         | 
| 8 8 | 
             
              gem.platform    = Gem::Platform::RUBY
         | 
| 9 9 | 
             
              gem.authors     = 'Michael van Rooijen'
         | 
| 10 10 | 
             
              gem.email       = 'meskyanichi@gmail.com'
         | 
| 11 11 | 
             
              gem.homepage    = 'http://hirefireapp.com/'
         | 
| 12 | 
            -
              gem.summary     = %|HireFireApp.com - The Heroku Worker  | 
| 13 | 
            -
              gem.description = %|HireFireApp.com - The Heroku Worker  | 
| 12 | 
            +
              gem.summary     = %|HireFireApp.com - The Heroku Worker Manager - Save money and scale at the same time!|
         | 
| 13 | 
            +
              gem.description = %|HireFireApp.com - The Heroku Worker Manager - Save money and scale at the same time! We monitor your applications by the minute!|
         | 
| 14 14 |  | 
| 15 15 | 
             
              # Files and folder that need to be compiled in to the Ruby Gem
         | 
| 16 16 | 
             
              gem.files         = %x[git ls-files].split("\n")
         | 
| 17 17 | 
             
              gem.executables   = ['hirefireapp']
         | 
| 18 18 | 
             
              gem.require_path  = 'lib'
         | 
| 19 19 |  | 
| 20 | 
            -
            end
         | 
| 20 | 
            +
            end
         | 
| @@ -6,19 +6,20 @@ module HireFireApp | |
| 6 6 | 
             
                ##
         | 
| 7 7 | 
             
                # Initialize the Rack Middleware by setting the app instance
         | 
| 8 8 | 
             
                # as well as allowing HireFire to request information via the token uri.
         | 
| 9 | 
            +
                #
         | 
| 9 10 | 
             
                def initialize(app)
         | 
| 10 11 | 
             
                  @app   = app
         | 
| 11 12 | 
             
                  @token = ENV['HIREFIREAPP_TOKEN']
         | 
| 12 13 | 
             
                end
         | 
| 13 14 |  | 
| 14 15 | 
             
                ##
         | 
| 15 | 
            -
                # If  | 
| 16 | 
            -
                #  | 
| 17 | 
            -
                #  | 
| 16 | 
            +
                # Simple router. If a request come in at the "test" url (the url to test if HireFire is properly installed)
         | 
| 17 | 
            +
                # then we return information about the current environment (orm, odm, kvs, worker library, etc). Returns "Not Found"
         | 
| 18 | 
            +
                # and specified "what wasn't found" in case the environment isn't complete (e.g. the worker library could not be found).
         | 
| 19 | 
            +
                #
         | 
| 20 | 
            +
                # HireFireApp.com will always ping to the "info?" url. This will return JSON format containing the current job queue
         | 
| 21 | 
            +
                # for the given worker library, as well as the queue_wait_time
         | 
| 18 22 | 
             
                #
         | 
| 19 | 
            -
                # Once the job_count has been determined, we build a simple JSON string object and
         | 
| 20 | 
            -
                # create a rack-based json response with 200 status. This will be returned to the HireFire service
         | 
| 21 | 
            -
                # in order to determine what actions to take in terms of scaling up or down.
         | 
| 22 23 | 
             
                def call(env)
         | 
| 23 24 | 
             
                  @env = env
         | 
| 24 25 |  | 
| @@ -32,22 +33,35 @@ module HireFireApp | |
| 32 33 | 
             
                end
         | 
| 33 34 |  | 
| 34 35 | 
             
                ##
         | 
| 35 | 
            -
                # Response body
         | 
| 36 | 
            +
                # Response body - This is the data that gets returned to the requester
         | 
| 37 | 
            +
                # depending on which URL was requested.
         | 
| 38 | 
            +
                #
         | 
| 36 39 | 
             
                def each(&block)
         | 
| 37 40 | 
             
                  if test?
         | 
| 38 41 | 
             
                    block.call "[HireFireApp: #{ok}] Worker: #{worker} - Mapper: #{mapper}"
         | 
| 39 42 | 
             
                  elsif info?
         | 
| 40 | 
            -
                    block.call %|{"job_count":#{job_count || 'null'}}|
         | 
| 43 | 
            +
                    block.call %|{"job_count":#{job_count || 'null'}, "queue_wait_time":#{queue_wait_time}}|
         | 
| 41 44 | 
             
                  end
         | 
| 42 45 | 
             
                end
         | 
| 43 46 |  | 
| 44 47 | 
             
                private
         | 
| 45 48 |  | 
| 49 | 
            +
                ##
         | 
| 50 | 
            +
                # Returns the time it took to allow the request
         | 
| 51 | 
            +
                # (delayed by the queue) in miliseconds
         | 
| 52 | 
            +
                #
         | 
| 53 | 
            +
                # @request [Integer] the queue wait time in miliseconds
         | 
| 54 | 
            +
                #
         | 
| 55 | 
            +
                def queue_wait_time
         | 
| 56 | 
            +
                  @env["HTTP_X_HEROKU_QUEUE_WAIT_TIME"].to_i
         | 
| 57 | 
            +
                end
         | 
| 58 | 
            +
             | 
| 46 59 | 
             
                ##
         | 
| 47 60 | 
             
                # Counts the amount of jobs that are currently queued
         | 
| 48 61 | 
             
                # and show be processed as soon as possible (aka the ones that are pending)
         | 
| 49 62 | 
             
                #
         | 
| 50 63 | 
             
                # @returns [Fixnum, nil] job_count returns nil if something went wrong
         | 
| 64 | 
            +
                #
         | 
| 51 65 | 
             
                def job_count
         | 
| 52 66 | 
             
                  begin
         | 
| 53 67 | 
             
                    if defined?(Delayed::Worker)
         | 
| @@ -69,6 +83,7 @@ module HireFireApp | |
| 69 83 | 
             
                # exist, and we'll have to use the old :conditions hash notation.
         | 
| 70 84 | 
             
                #
         | 
| 71 85 | 
             
                # @returns [Fixnum] delayed_job_count the amount of jobs currently pending
         | 
| 86 | 
            +
                #
         | 
| 72 87 | 
             
                def count_delayed_job
         | 
| 73 88 | 
             
                  if defined?(ActiveRecord) and Delayed::Worker.backend.to_s =~ /ActiveRecord/
         | 
| 74 89 | 
             
                    if defined?(ActiveRecord::Relation)
         | 
| @@ -95,6 +110,7 @@ module HireFireApp | |
| 95 110 | 
             
                #
         | 
| 96 111 | 
             
                # @returns [Fixnum] resque_job_count
         | 
| 97 112 | 
             
                #  the number of jobs pending + the amount of workers currently working
         | 
| 113 | 
            +
                #
         | 
| 98 114 | 
             
                def count_resque
         | 
| 99 115 | 
             
                  Resque.info[:pending].to_i + Resque.info[:working].to_i
         | 
| 100 116 | 
             
                end
         | 
| @@ -103,6 +119,7 @@ module HireFireApp | |
| 103 119 | 
             
                # Returns the name of the mapper, or "Not Found" if not found
         | 
| 104 120 | 
             
                #
         | 
| 105 121 | 
             
                # @returns [String]
         | 
| 122 | 
            +
                #
         | 
| 106 123 | 
             
                def mapper
         | 
| 107 124 | 
             
                  if defined?(Redis) and defined?(Resque)
         | 
| 108 125 | 
             
                    "Redis"
         | 
| @@ -123,6 +140,7 @@ module HireFireApp | |
| 123 140 | 
             
                # Returns the name of the worker type, or "Not Found" if not found
         | 
| 124 141 | 
             
                #
         | 
| 125 142 | 
             
                # @returns [String]
         | 
| 143 | 
            +
                #
         | 
| 126 144 | 
             
                def worker
         | 
| 127 145 | 
             
                  if defined?(Delayed::Job)
         | 
| 128 146 | 
             
                    "Delayed Job"
         | 
| @@ -137,6 +155,7 @@ module HireFireApp | |
| 137 155 | 
             
                # Returns "OK" if both the mapper and worker were found
         | 
| 138 156 | 
             
                #
         | 
| 139 157 | 
             
                # @returns [String]
         | 
| 158 | 
            +
                #
         | 
| 140 159 | 
             
                def ok
         | 
| 141 160 | 
             
                  if mapper =~ /Not Found/ or worker =~ /Not Found/
         | 
| 142 161 | 
             
                    "Incomplete"
         | 
| @@ -149,6 +168,7 @@ module HireFireApp | |
| 149 168 | 
             
                # Returns true if the REQUEST_PATH matches the test url
         | 
| 150 169 | 
             
                #
         | 
| 151 170 | 
             
                # @returns [String]
         | 
| 171 | 
            +
                #
         | 
| 152 172 | 
             
                def test?
         | 
| 153 173 | 
             
                  @env['REQUEST_PATH'] == "/hirefireapp/test"
         | 
| 154 174 | 
             
                end
         | 
| @@ -157,6 +177,7 @@ module HireFireApp | |
| 157 177 | 
             
                # Returns true if the REQUEST_PATH matches the info url
         | 
| 158 178 | 
             
                #
         | 
| 159 179 | 
             
                # @returns [String]
         | 
| 180 | 
            +
                #
         | 
| 160 181 | 
             
                def info?
         | 
| 161 182 | 
             
                  @env['REQUEST_PATH'] == "/hirefireapp/#{@token}/info"
         | 
| 162 183 | 
             
                end
         | 
    
        metadata
    CHANGED
    
    | @@ -2,7 +2,7 @@ | |
| 2 2 | 
             
            name: hirefireapp
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 4 4 | 
             
              prerelease: 
         | 
| 5 | 
            -
              version: 0.0. | 
| 5 | 
            +
              version: 0.0.2
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 7 | 
             
            authors: 
         | 
| 8 8 | 
             
            - Michael van Rooijen
         | 
| @@ -10,11 +10,11 @@ autorequire: | |
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 12 |  | 
| 13 | 
            -
            date: 2011- | 
| 13 | 
            +
            date: 2011-07-25 00:00:00 +02:00
         | 
| 14 14 | 
             
            default_executable: 
         | 
| 15 15 | 
             
            dependencies: []
         | 
| 16 16 |  | 
| 17 | 
            -
            description: HireFireApp.com - The Heroku Worker  | 
| 17 | 
            +
            description: HireFireApp.com - The Heroku Worker Manager - Save money and scale at the same time! We monitor your applications by the minute!
         | 
| 18 18 | 
             
            email: meskyanichi@gmail.com
         | 
| 19 19 | 
             
            executables: 
         | 
| 20 20 | 
             
            - hirefireapp
         | 
| @@ -57,6 +57,6 @@ rubyforge_project: | |
| 57 57 | 
             
            rubygems_version: 1.6.2
         | 
| 58 58 | 
             
            signing_key: 
         | 
| 59 59 | 
             
            specification_version: 3
         | 
| 60 | 
            -
            summary: HireFireApp.com - The Heroku Worker  | 
| 60 | 
            +
            summary: HireFireApp.com - The Heroku Worker Manager - Save money and scale at the same time!
         | 
| 61 61 | 
             
            test_files: []
         | 
| 62 62 |  |