2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-01-24 10:04:31 +01:00
|
|
|
module LockableConcern
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
|
|
|
def lock_action(key)
|
2024-06-14 11:34:41 +02:00
|
|
|
lock = Kredis.flag(key)
|
2024-01-24 10:04:31 +01:00
|
|
|
head :locked and return if lock.marked?
|
|
|
|
|
|
|
|
lock.mark(expires_in: 10.seconds)
|
|
|
|
|
|
|
|
yield
|
|
|
|
|
|
|
|
lock.remove
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|