Module: ConcernsOnRails::Controllers::Idempotentable::ClassMethods
- Defined in:
- lib/concerns_on_rails/controllers/idempotentable.rb
Instance Method Summary collapse
-
#idempotent_actions(*actions, ttl: 86_400, lock_ttl: 60, header: DEFAULT_HEADER, required: false) ⇒ Object
Declare idempotent actions.
Instance Method Details
#idempotent_actions(*actions, ttl: 86_400, lock_ttl: 60, header: DEFAULT_HEADER, required: false) ⇒ Object
Declare idempotent actions. ‘ttl:` is the cached-response lifetime, `lock_ttl:` the in-flight claim lifetime (kept short so a crashed worker cannot wedge a key), `header:` the request header to read, and `required:` whether a missing key is a 400. Each call appends a rule; the first rule listing the current action wins.
68 69 70 71 72 73 74 |
# File 'lib/concerns_on_rails/controllers/idempotentable.rb', line 68 def idempotent_actions(*actions, ttl: 86_400, lock_ttl: 60, header: DEFAULT_HEADER, required: false) actions = actions.flatten.map(&:to_s) validate_idempotent!(actions, ttl: ttl, lock_ttl: lock_ttl, header: header, required: required) rule = { actions: actions, ttl: ttl.to_i, lock_ttl: lock_ttl.to_i, header: header.to_s, required: required } self.idempotency_rules = idempotency_rules + [rule] end |