Module: Dapp::Dapp::Lock
- Included in:
- Dapp::Dapp
- Defined in:
- lib/dapp/dapp/lock.rb
Instance Method Summary collapse
- #_lock(name, type) ⇒ Object
- #lock(name, *_args, default_timeout: 300, type: :dapp, **kwargs, &blk) ⇒ Object
- #lock_path(type) ⇒ Object
Instance Method Details
#_lock(name, type) ⇒ Object
17 18 19 20 21 |
# File 'lib/dapp/dapp/lock.rb', line 17 def _lock(name, type) @_locks ||= {} @_locks[type] ||= {} @_locks[type][name] ||= ::Dapp::Dimg::Lock::File.new(lock_path(type), name) end |
#lock(name, *_args, default_timeout: 300, type: :dapp, **kwargs, &blk) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/dapp/dapp/lock.rb', line 23 def lock(name, *_args, default_timeout: 300, type: :dapp, **kwargs, &blk) if dry_run? yield if block_given? else timeout = [:lock_timeout] || default_timeout _lock(name, type).synchronize( timeout: timeout, on_wait: proc do |&do_wait| log_secondary_process( t(code: 'process.waiting_resouce_lock', data: { name: name }), short: true, &do_wait ) end, **kwargs, &blk ) end end |
#lock_path(type) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/dapp/dapp/lock.rb', line 4 def lock_path(type) case type when :dapp build_path.join('locks') when :global Pathname.new("/tmp/dapp.global.locks").tap do |p| FileUtils.mkdir_p p.to_s end else raise end end |