Class: Imap::Backup::Account::Locker
- Inherits:
-
Object
- Object
- Imap::Backup::Account::Locker
- Defined in:
- lib/imap/backup/account/locker.rb
Instance Attribute Summary collapse
-
#account ⇒ Object
readonly
Returns the value of attribute account.
Instance Method Summary collapse
-
#initialize(account:) ⇒ Locker
constructor
A new instance of Locker.
- #with_lock(&block) ⇒ Object
Constructor Details
#initialize(account:) ⇒ Locker
Returns a new instance of Locker.
13 14 15 |
# File 'lib/imap/backup/account/locker.rb', line 13 def initialize(account:) @account = account end |
Instance Attribute Details
#account ⇒ Object (readonly)
Returns the value of attribute account.
10 11 12 |
# File 'lib/imap/backup/account/locker.rb', line 10 def account @account end |
Instance Method Details
#with_lock(&block) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/imap/backup/account/locker.rb', line 17 def with_lock(&block) lockfile = Lockfile.new(path: account.lockfile_path) if lockfile.exists? if !lockfile.stale? raise Lockfile::LockfileExistsError, "Lockfile '#{account.lockfile_path}' exists and is not stale." end Logger.logger.info("Stale lockfile '#{account.lockfile_path}' found. Removing it.") lockfile.remove else Account::FolderEnsurer.new(account: account).run end begin lockfile.with_lock do block.call end rescue Lockfile::ProcessStartTimeUnavailableError block.call end end |