Class: Zizq::Configuration
- Inherits:
-
Object
- Object
- Zizq::Configuration
- Defined in:
- lib/zizq/configuration.rb
Overview
Global configuration for the Zizq client.
The configuration stores only client-level concerns: server URL, serialization format, and logger. Worker-specific settings (queues, threads, etc.) are passed directly to the Worker.
See: [‘Zizq::configure]`. See: [`Zizq::configuration]`.
Defined Under Namespace
Classes: Identity
Instance Attribute Summary collapse
-
#dequeue_middleware ⇒ Object
readonly
Middleware chain for dequeue/dispatch.
-
#enqueue_middleware ⇒ Object
readonly
Middleware chain for enqueue.
-
#format ⇒ Object
Choice of content-type encoding used in communication with the Zizq server.
-
#logger ⇒ Object
Logger instance to which to write log messages.
-
#read_timeout ⇒ Object
Per-operation socket I/O timeout (seconds) for regular API calls (enqueue, queries, mutations).
-
#stream_idle_timeout ⇒ Object
Per-operation socket I/O timeout (seconds) for the long-lived ‘#take_jobs` stream.
-
#tls ⇒ Object
TLS options for connecting to the server over HTTPS.
-
#url ⇒ Object
Base URL of the Zizq server (default: “localhost:7890”).
Instance Method Summary collapse
-
#dispatcher ⇒ Object
The job dispatcher.
-
#dispatcher=(dispatcher) ⇒ Object
Set the dispatcher to a custom dispatcher implementation.
-
#initialize ⇒ Configuration
constructor
: () -> void.
-
#ssl_context ⇒ Object
Build an OpenSSL::SSL::SSLContext from the TLS options, or nil if no TLS options are configured.
-
#validate! ⇒ Object
Validates that required configuration is present.
Constructor Details
#initialize ⇒ Configuration
: () -> void
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/zizq/configuration.rb', line 74 def initialize #: () -> void @url = "http://localhost:7890" @format = :msgpack @logger = Logger.new($stdout, level: Logger::INFO) @tls = nil @read_timeout = 30 @stream_idle_timeout = 30 @enqueue_middleware = Middleware::Chain.new(Identity.new) @dequeue_middleware = Middleware::Chain.new(Zizq::Job) end |
Instance Attribute Details
#dequeue_middleware ⇒ Object (readonly)
Middleware chain for dequeue/dispatch. Each middleware receives a ‘Resources::Job` and a chain to continue.
72 73 74 |
# File 'lib/zizq/configuration.rb', line 72 def dequeue_middleware @dequeue_middleware end |
#enqueue_middleware ⇒ Object (readonly)
Middleware chain for enqueue. Each middleware receives an ‘EnqueueRequest` and a chain to continue.
68 69 70 |
# File 'lib/zizq/configuration.rb', line 68 def enqueue_middleware @enqueue_middleware end |
#format ⇒ Object
Choice of content-type encoding used in communication with the Zizq server.
One of: ‘:json`, `:msgpack` (default)
27 28 29 |
# File 'lib/zizq/configuration.rb', line 27 def format @format end |
#logger ⇒ Object
Logger instance to which to write log messages.
30 31 32 |
# File 'lib/zizq/configuration.rb', line 30 def logger @logger end |
#read_timeout ⇒ Object
Per-operation socket I/O timeout (seconds) for regular API calls (enqueue, queries, mutations). Each socket read/write is bounded by this value. A request whose handshake or any single read exceeds this raises ‘IO::TimeoutError`.
Default: 30.
51 52 53 |
# File 'lib/zizq/configuration.rb', line 51 def read_timeout @read_timeout end |
#stream_idle_timeout ⇒ Object
Per-operation socket I/O timeout (seconds) for the long-lived ‘#take_jobs` stream. The server sends heartbeats every ~3 seconds, so each read returns within that window and keeps the connection alive; the connection only times out if the server falls silent for longer than this. The Worker catches the resulting error and reconnects with backoff.
Should be comfortably above the server’s heartbeat interval to avoid false-positive disconnects.
Default: 30.
64 65 66 |
# File 'lib/zizq/configuration.rb', line 64 def stream_idle_timeout @stream_idle_timeout end |
#tls ⇒ Object
TLS options for connecting to the server over HTTPS.
All values may be PEM-encoded strings or file paths.
{
ca: "path/to/ca-cert.pem", # CA certificate for server verification
client_cert: "path/to/client-cert.pem", # Client certificate for mTLS
client_key: "path/to/client-key.pem", # Client private key for mTLS
}
Note: Mutual TLS support requires a Zizq Pro license on the server.
43 44 45 |
# File 'lib/zizq/configuration.rb', line 43 def tls @tls end |
#url ⇒ Object
Base URL of the Zizq server (default: “localhost:7890”).
21 22 23 |
# File 'lib/zizq/configuration.rb', line 21 def url @url end |
Instance Method Details
#dispatcher ⇒ Object
The job dispatcher. This is the terminal of the dequeue middleware chain. Defaults to ‘Zizq::Job` which finds and executes jobs written by mixing in the `Zizq::Job` module.
89 90 91 |
# File 'lib/zizq/configuration.rb', line 89 def dispatcher #: () -> Zizq::dispatcher @dequeue_middleware.terminal end |
#dispatcher=(dispatcher) ⇒ Object
Set the dispatcher to a custom dispatcher implementation.
A dispatcher is any object that responds to ‘#call` with a `Zizq::Resources::Job` instance and performs that job through some application-specific logic.
This is the terminal of the dequeue middleware chain.
Any errors raised by the dispatcher will result in the normal backoff/retry behaviour. Jobs are acknowledged automatically on success.
103 104 105 |
# File 'lib/zizq/configuration.rb', line 103 def dispatcher=(dispatcher) #: (Zizq::dispatcher) -> void @dequeue_middleware.terminal = dispatcher end |
#ssl_context ⇒ Object
Build an OpenSSL::SSL::SSLContext from the TLS options, or nil if no TLS options are configured.
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/zizq/configuration.rb', line 130 def ssl_context #: () -> OpenSSL::SSL::SSLContext? tls = @tls return nil unless tls ctx = OpenSSL::SSL::SSLContext.new if (ca = tls[:ca]) store = OpenSSL::X509::Store.new store.add_cert(load_cert(ca)) ctx.cert_store = store ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER end if (client_cert = tls[:client_cert]) ctx.cert = load_cert(client_cert) end if (client_key = tls[:client_key]) ctx.key = load_key(client_key) end ctx end |
#validate! ⇒ Object
Validates that required configuration is present.
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/zizq/configuration.rb', line 108 def validate! #: () -> void raise ArgumentError, "Zizq.configure: url is required" if url.empty? unless %i[msgpack json].include?(format) raise ArgumentError, "Zizq.configure: format must be :msgpack or :json, got #{format.inspect}" end unless read_timeout.is_a?(Numeric) && read_timeout > 0 raise ArgumentError, "Zizq.configure: read_timeout must be a positive number, got #{read_timeout.inspect}" end unless stream_idle_timeout.is_a?(Numeric) && stream_idle_timeout > 0 raise ArgumentError, "Zizq.configure: stream_idle_timeout must be a positive number, got #{stream_idle_timeout.inspect}" end tls = @tls validate_tls!(tls) if tls end |