Class: Wurk::Collapse::ClientMiddleware
- Inherits:
-
Object
- Object
- Wurk::Collapse::ClientMiddleware
- Includes:
- JobUtil, Middleware::ClientMiddleware
- Defined in:
- lib/wurk/collapse.rb
Overview
Client middleware — the collapse decision, taken once every other middleware has had the payload.
Prepended, and it decides after its yield. Both halves are load-bearing.
Nothing in the client chain writes to Redis — Wurk::Client#push does that
only once invoke_chain has handed a payload back — so a middleware is
free to run the rest of the chain and then halt the push by returning nil.
Deciding on the way out means the payload Debounce stores in
schedule carries everything the enrichers stamped on it (bid, locale,
cattr, traceparent), so a debounced job really is the scheduled job a
perform_in would have written rather than a stripped-down cousin. Sitting
outermost is what keeps that true for the middleware a host installs later
at boot: Unique.enable!, Encryption.enable! and Telemetry.install!
all add, which appends inside this one.
Instance Method Summary collapse
- #call(_worker, job, _queue, redis_pool) ⇒ Object
-
#normalize_item(item) ⇒ Object
included
from JobUtil
Validate → merge class/default options → stringify → assign jid & created_at → strip transient keys.
- #now_in_millis ⇒ Object included from JobUtil
- #validate(item) ⇒ Object included from JobUtil
-
#verify_json(item) ⇒ Object
included
from JobUtil
Walk args; report the first non-JSON-native value according to the configured strict mode.
Instance Method Details
#call(_worker, job, _queue, redis_pool) ⇒ Object
256 257 258 259 260 261 262 263 264 265 266 |
# File 'lib/wurk/collapse.rb', line 256 def call(_worker, job, _queue, redis_pool) # One Hash lookup for a job that declares nothing, which is every job in # an app that uses neither policy. return yield if job[Wurk::Collapse::OPTION].nil? policy = Wurk::Collapse.policy_for(job) payload = yield return nil if payload.nil? decide(policy, payload, redis_pool) end |
#normalize_item(item) ⇒ Object Originally defined in module JobUtil
Validate → merge class/default options → stringify → assign jid & created_at → strip transient keys. Returns the canonical payload.
#now_in_millis ⇒ Object Originally defined in module JobUtil
#validate(item) ⇒ Object Originally defined in module JobUtil
#verify_json(item) ⇒ Object Originally defined in module JobUtil
Walk args; report the first non-JSON-native value according to the configured strict mode. Hash keys must be Strings.