lock.rb 767 B

123456789101112131415161718192021222324252627
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module Gql::Mutations
  3. class System::Setup::Lock < BaseMutation
  4. RESOURCE = 'Zammad::System::Setup'.freeze
  5. TTL = (60.minutes * 60.seconds * 1000).to_i.freeze
  6. argument :ttl, Integer, 'Critical section lock life time.', required: false
  7. description 'Lock critical section, system setup.'
  8. field :resource, String, 'Critical section resoure name.', null: true
  9. field :value, String, 'Critical section resoure value.', null: true
  10. def self.authorize(...)
  11. true
  12. end
  13. def resolve(ttl: TTL)
  14. Service::System::CheckSetup.new!
  15. Service::ExecuteLockedBlock.locked!(RESOURCE)
  16. Service::ExecuteLockedBlock.lock(RESOURCE, ttl)
  17. end
  18. end
  19. end