Module: GenevaDrive::JobOptions Private
- Defined in:
- lib/geneva_drive/job_options.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Validation helper for Active Job option hashes passed through the workflow DSL
(set_step_job_options, step(job_options: ...), and workflow.step_job_options=).
Active Job itself silently ignores unknown keys in set — a typo like
piority: would never raise, and the workflow would just run at the default
priority. This helper enforces the known key set so misconfigurations surface
at definition time, or at assignment time for per-instance overrides.
The allowed keys mirror what ActiveJob::Core#set actually consumes.
Constant Summary collapse
- ALLOWED_KEYS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Keys that Active Job's
setrecognizes. SeeActiveJob::Core#setin activejob/lib/active_job/core.rb. %i[wait wait_until queue priority].freeze
Class Method Summary collapse
-
.validate!(options, context:) ⇒ Hash{Symbol=>Object}
private
Validates a job options hash and returns a symbolized copy.
- .validate_value!(key, value, context) ⇒ Object private
Class Method Details
.validate!(options, context:) ⇒ Hash{Symbol=>Object}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Validates a job options hash and returns a symbolized copy.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/geneva_drive/job_options.rb', line 29 def self.validate!(, context:) hash = begin .to_h rescue NoMethodError, TypeError, ArgumentError raise GenevaDrive::StepConfigurationError, "#{context} has invalid job_options: cannot coerce #{.class} to a Hash via #to_h" end symbolized = hash.symbolize_keys unknown = symbolized.keys - ALLOWED_KEYS unless unknown.empty? raise GenevaDrive::StepConfigurationError, "#{context} has unknown job_options key(s): #{unknown.map(&:inspect).join(", ")}. " \ "Active Job only recognizes: #{ALLOWED_KEYS.map(&:inspect).join(", ")}" end symbolized.each { |k, v| validate_value!(k, v, context) } symbolized end |
.validate_value!(key, value, context) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/geneva_drive/job_options.rb', line 51 def self.validate_value!(key, value, context) return if value.nil? valid = case key when :wait value.respond_to?(:to_i) && value.to_i >= 0 when :wait_until value.respond_to?(:to_time) || value.respond_to?(:to_f) when :queue value.is_a?(String) || value.is_a?(Symbol) when :priority value.is_a?(Integer) end return if valid raise GenevaDrive::StepConfigurationError, "#{context} has invalid job_options[#{key.inspect}]: #{value.inspect} (#{value.class})" end |