demarches-normaliennes/app/controllers/concerns/lockable_concern.rb
2024-08-22 09:26:48 +02:00

18 lines
293 B
Ruby

# frozen_string_literal: true
module LockableConcern
extend ActiveSupport::Concern
included do
def lock_action(key)
lock = Kredis.flag(key)
head :locked and return if lock.marked?
lock.mark(expires_in: 10.seconds)
yield
lock.remove
end
end
end