Class: RestCore::Timeout
- Inherits:
-
Object
show all
- Includes:
- Middleware
- Defined in:
- lib/rest-core/middleware/timeout.rb
Constant Summary
Constants included
from Middleware
Middleware::METHODS_WITH_PAYLOAD, Middleware::UNRESERVED
Constants included
from RestCore
ASYNC, CLIENT, DRY, FAIL, HIJACK, LOG, PROMISE, REQUEST_HEADERS, REQUEST_METHOD, REQUEST_PATH, REQUEST_PAYLOAD, REQUEST_QUERY, REQUEST_URI, RESPONSE_BODY, RESPONSE_HEADERS, RESPONSE_KEY, RESPONSE_SOCKET, RESPONSE_STATUS, Simple, TIMER, Universal, VERSION
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Middleware
#contain_binary?, contain_binary?, #error_callback, #escape, escape, #fail, #give_promise, #has_payload?, has_payload?, #id, included, #log, #merge_hash, merge_hash, percent_encode, #percent_encode, #request_uri, request_uri, #run, string_keys, #string_keys
Methods included from RestCore
eagerload, id
Class Method Details
.members ⇒ Object
8
|
# File 'lib/rest-core/middleware/timeout.rb', line 8
def self.members; [:timeout]; end
|
Instance Method Details
#call(env, &k) ⇒ Object
11
12
13
14
|
# File 'lib/rest-core/middleware/timeout.rb', line 11
def call env, &k
return app.call(env, &k) if env[DRY] || timeout(env) == 0
process(env, &k)
end
|
#process(env, &k) ⇒ Object
16
17
18
19
20
21
22
|
# File 'lib/rest-core/middleware/timeout.rb', line 16
def process env, &k
timer = Timer.new(timeout(env), timeout_error)
app.call(env.merge(TIMER => timer), &k)
rescue Exception
timer.cancel
raise
end
|
#timeout_error ⇒ Object
24
25
26
|
# File 'lib/rest-core/middleware/timeout.rb', line 24
def timeout_error
::Timeout::Error.new('execution expired')
end
|