Class: WorklessChecker
- Inherits:
-
Object
- Object
- WorklessChecker
- Defined in:
- lib/workless/middleware/workless_checker.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#empty?(response) ⇒ Boolean
fix issue if response’s body is a Proc.
-
#file?(headers) ⇒ Boolean
if send file?.
-
#initialize(app) ⇒ WorklessChecker
constructor
A new instance of WorklessChecker.
Constructor Details
#initialize(app) ⇒ WorklessChecker
Returns a new instance of WorklessChecker.
2 3 4 |
# File 'lib/workless/middleware/workless_checker.rb', line 2 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/workless/middleware/workless_checker.rb', line 6 def call(env) status, headers, response = @app.call(env) return [status, headers, response] if file?(headers) || empty?(response) Delayed::Job.scaler.up unless Delayed::Job.scaler.jobs.empty? [status, headers, response] end |
#empty?(response) ⇒ Boolean
fix issue if response’s body is a Proc
16 17 18 19 20 21 22 |
# File 'lib/workless/middleware/workless_checker.rb', line 16 def empty?(response) # response may be ["Not Found"], ["Move Permanently"], etc. (response.is_a?(Array) && response.size <= 1) || !response.respond_to?(:body) || !response.body.respond_to?(:empty?) || response.body.empty? end |
#file?(headers) ⇒ Boolean
if send file?
25 26 27 |
# File 'lib/workless/middleware/workless_checker.rb', line 25 def file?(headers) headers['Content-Transfer-Encoding'] == 'binary' end |