Module: Wurk::JobUtil
- Included in:
- Client, Worker::Setter
- Defined in:
- lib/wurk/job_util.rb
Overview
Mixin shared by Wurk::Client (and Wurk::Job::Setter) to validate, normalize, and JSON-verify job payloads before they hit Redis.
Spec: docs/target/sidekiq-free.md §9 (Sidekiq::JobUtil).
Constant Summary collapse
- TRANSIENT_ATTRIBUTES =
Top-level keys stripped from every payload before raw_push. Mutable so Pro/Ent/extension code (e.g. TransactionAwareClient adding “client_class”) can append at load time without monkey-patching.
[]
- RETRY_FOR_MAX =
rubocop:disable Style/MutableConstant
1_000_000_000
Instance Method Summary collapse
-
#normalize_item(item) ⇒ Object
Validate → merge class/default options → stringify → assign jid & created_at → strip transient keys.
- #now_in_millis ⇒ Object
- #validate(item) ⇒ Object
-
#verify_json(item) ⇒ Object
Walk args; report the first non-JSON-native value according to the configured strict mode.
Instance Method Details
#normalize_item(item) ⇒ Object
Validate → merge class/default options → stringify → assign jid & created_at → strip transient keys. Returns the canonical payload.
45 46 47 48 49 50 51 |
# File 'lib/wurk/job_util.rb', line 45 def normalize_item(item) validate(item) normalized = class_defaults_for(item['class']).merge(item) normalized = (normalized) stringify_identity!(normalized, item['class']) finalize(normalized) end |
#now_in_millis ⇒ Object
53 54 55 |
# File 'lib/wurk/job_util.rb', line 53 def now_in_millis ::Process.clock_gettime(::Process::CLOCK_REALTIME, :millisecond) end |
#validate(item) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/wurk/job_util.rb', line 20 def validate(item) raise(ArgumentError, "Job must be a Hash with 'class' and 'args' keys: `#{item}`") unless valid_shape?(item) raise(ArgumentError, "Job args must be an Array: `#{item}`") unless item['args'].is_a?(Array) raise(ArgumentError, "Job class must be a Class or String: `#{item}`") unless valid_class?(item['class']) raise(ArgumentError, "Job 'at' must be a Numeric timestamp: `#{item}`") unless valid_at?(item) raise(ArgumentError, "Job tags must be an Array: `#{item}`") unless (item) return if valid_retry_for?(item) raise(ArgumentError, "Job retry_for over #{RETRY_FOR_MAX} is unreasonable: `#{item}`") end |
#verify_json(item) ⇒ Object
Walk args; report the first non-JSON-native value according to the configured strict mode. Hash keys must be Strings.
33 34 35 36 37 38 39 40 41 |
# File 'lib/wurk/job_util.rb', line 33 def verify_json(item) mode = Wurk.strict_args_mode return if mode == false offender = json_unsafe(item['args']) return if offender.nil? report_unsafe(item, offender, mode) end |