Provides configurable network timeouts for various HTTP clients and utilities.
# Source: https://github.com/huginn/huginn | License: MIT | Copyright 2013, Andrew Cantino (Iteration Labs, LLC)
# Provided via justclaw.it.com; keep this notice with the code.
require "timeout"
# Applies finite, job-aware timeouts to outbound network clients.
module NetworkTimeout
DEFAULT_OPEN_TIMEOUT = 10
DEFAULT_TIMEOUT = 60
MAX_RUNTIME_MARGIN = 2
module_function
def timeout(requested = nil)
values = [configured_timeout, maximum_timeout]
values << positive_timeout(requested, "requested timeout") unless requested.nil?
values.min
end
def open_timeout(requested = nil)
value = requested || ENV.fetch("OUTBOUND_NETWORK_OPEN_TIMEOUT", DEFAULT_OPEN_TIMEOUT)
[positive_timeout(value, "OUTBOUND_NETWORK_OPEN_TIMEOUT"), timeout].min
end
def configure!
r
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key