History

[lock] capture amount of attempts taken when obtaining a lock

Just because it's interesting to me.

Sebastian Thiel committed 5 years ago

Commit 7fafa3e1 parent 34d3c5a1 file · +5 −2Browse files

Unified · Split

git-lock/src/acquire.rs+5−2
@@ -45,8 +45,8 @@ quick_error! { · 44 unmodified lines
45 from()45 from()
46 source(err)46 source(err)
47 }47 }
48 PermanentlyLocked { resource_path: PathBuf, mode: Fail } {48 PermanentlyLocked { resource_path: PathBuf, mode: Fail, attempts: usize } {
49 display("The lock for resource '{} could not be obtained {}. The lockfile at '{}{}' might need manual deletion.", resource_path.display(), mode, resource_path.display(), super::DOT_SUFFIX)49 display("The lock for resource '{} could not be obtained {} after {} attempt(s). The lockfile at '{}{}' might need manual deletion.", resource_path.display(), mode, attempts, resource_path.display(), super::DOT_SUFFIX)
50 }50 }
51 }51 }
52}52}
@@ -107,10 +107,12 @@ fn lock_with_mode<T>( · 54 unmodified lines
107 use std::io::ErrorKind::*;107 use std::io::ErrorKind::*;
108 let (directory, cleanup) = dir_cleanup(boundary_directory);108 let (directory, cleanup) = dir_cleanup(boundary_directory);
109 let lock_path = add_lock_suffix(resource);109 let lock_path = add_lock_suffix(resource);
110 let mut attempts = 1;
110 match mode {111 match mode {
111 Fail::Immediately => try_lock(&lock_path, directory, cleanup),112 Fail::Immediately => try_lock(&lock_path, directory, cleanup),
112 Fail::AfterDurationWithBackoff(time) => {113 Fail::AfterDurationWithBackoff(time) => {
113 for wait in backoff::Exponential::default_with_random().until_no_remaining(time) {114 for wait in backoff::Exponential::default_with_random().until_no_remaining(time) {
115 attempts += 1;
114 match try_lock(&lock_path, directory, cleanup.clone()) {116 match try_lock(&lock_path, directory, cleanup.clone()) {
115 Ok(v) => return Ok(v),117 Ok(v) => return Ok(v),
116 Err(err) if err.kind() == AlreadyExists => {118 Err(err) if err.kind() == AlreadyExists => {
@@ -127,6 +129,7 @@ fn lock_with_mode<T>( · 10 unmodified lines
127 AlreadyExists => Error::PermanentlyLocked {129 AlreadyExists => Error::PermanentlyLocked {
128 resource_path: resource.into(),130 resource_path: resource.into(),
129 mode,131 mode,
132 attempts,
130 },133 },
131 _ => Error::Io(err),134 _ => Error::Io(err),
132 })135 })

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t