Class: HireFireApp::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/hirefireapp/middleware.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Middleware

Initialize the Rack Middleware by setting the app instance as well as allowing HireFire to request information via the token uri.



10
11
12
13
# File 'lib/hirefireapp/middleware.rb', line 10

def initialize(app)
  @app   = app
  @token = ENV['HIREFIREAPP_TOKEN'] || "development"
end

Instance Method Details

#call(env) ⇒ Object

Return a HTML response if the “test url” has been requested. Return a JSON requested if the “info url” has been requested.



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/hirefireapp/middleware.rb', line 19

def call(env)
  @env = env

  if test?
    [ 200, {'Content-Type' => 'text/html'}, self ]
  elsif info?
    [ 200, {'Content-Type' => 'application/json'}, self ]
  else
    @app.call(env)
  end
end

#each(&block) ⇒ Object

If the “test url” has been requested, we’ll return information regarding the HireFire installation in HTML format. If the “info url” has been regarding, we’ll return the job count for the worker library (if applicable) in JSON format.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/hirefireapp/middleware.rb', line 36

def each(&block)
  if test?
    out =  "\n"
    out << "[HireFire][Web]    OK\n"
    out << "[HireFire][Worker] #{worker_ok} (Library: #{worker_library}, Mapper: #{mapper_library})\n\n"

    if worker_library =~ /Not Found/
      out << "HireFire is able to manage your web dynos, but not your worker dynos.\n"
    else
      out << "HireFire is able to manage both your web, as well as your worker dynos."
    end

    block.call out
  elsif info?
    block.call %|{"job_count":#{job_count || "null"}}|
  end
end