File tree 2 files changed +28
-7
lines changed
2 files changed +28
-7
lines changed Original file line number Diff line number Diff line change @@ -70,12 +70,17 @@ def list(
70
70
print (json .dumps (response ))
71
71
72
72
@base .intercept_exception
73
- def create (
74
- self ,
75
- reason ,
76
- ):
73
+ def create (self , reason , timeout_secs = 300 ):
77
74
"""Create a lock."""
78
- print (base .get_client ().lock .create (reason ), file = sys .stdout )
75
+ response = base .get_client ().lock .create (reason , timeout_secs )
76
+ if response is False :
77
+ print (
78
+ "Unabled to lock within '{}'" .format (timeout_secs ),
79
+ file = sys .stderr ,
80
+ )
81
+ else :
82
+ # reponse contains lock ID
83
+ print (response , file = sys .stderr )
79
84
80
85
@base .intercept_exception
81
86
def delete (
Original file line number Diff line number Diff line change @@ -45,13 +45,15 @@ def list(self):
45
45
"""Retrieve the locks"""
46
46
return self .get ()
47
47
48
- def create (self , reason = None ):
48
+ def create (self , reason = None , timeout_secs = 300 ):
49
49
"""Create a new lock.
50
50
51
51
Arguments
52
52
---------
53
53
reason: str
54
54
Provide a reason for the lock.
55
+ timeout_secs: int
56
+ Time to wait for lock to be successful
55
57
56
58
Raises
57
59
------
@@ -64,7 +66,21 @@ def create(self, reason=None):
64
66
data = data ,
65
67
description = "lock/set_lock" ,
66
68
)
67
- return CaseInsensitiveDict (response .headers )["Location" ]
69
+ id = CaseInsensitiveDict (response .headers )["Location" ]
70
+
71
+ if timeout_secs == 0 :
72
+ return id
73
+ else :
74
+ try :
75
+ polling .poll (
76
+ lambda : self .get ()["locked" ],
77
+ step = 10 ,
78
+ poll_forever = False ,
79
+ timeout = timeout_secs ,
80
+ )
81
+ return id
82
+ except polling .TimeoutException :
83
+ return False
68
84
69
85
def delete (self , lock_id ):
70
86
"""Delete a lock.
You can’t perform that action at this time.
0 commit comments