-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use a mutex for registry CLI txs in webapp deployment commands (#957)
Part of [Service provider auctions for web deployments](https://www.notion.so/Service-provider-auctions-for-web-deployments-104a6b22d47280dbad51d28aa3a91d75) and https://git.vdb.to/cerc-io/stack-orchestrator/issues/948 - Add a registry mutex decorator over tx methods in `LaconicRegistryClient` wrapper - Required to allow multiple process to run webapp deployment tooling without running into account sequence errors when sending laconicd txs Reviewed-on: https://git.vdb.to/cerc-io/stack-orchestrator/pulls/957 Reviewed-by: ashwin <[email protected]> Co-authored-by: Prathamesh Musale <[email protected]> Co-committed-by: Prathamesh Musale <[email protected]>
- Loading branch information
1 parent
0c47da4
commit 4a7df2d
Showing
6 changed files
with
82 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import fcntl | ||
from functools import wraps | ||
|
||
# Define default file path for the lock | ||
DEFAULT_LOCK_FILE_PATH = "/tmp/registry_mutex_lock_file" | ||
|
||
|
||
def registry_mutex(): | ||
def decorator(func): | ||
@wraps(func) | ||
def wrapper(self, *args, **kwargs): | ||
lock_file_path = DEFAULT_LOCK_FILE_PATH | ||
if self.mutex_lock_file is not None: | ||
lock_file_path = self.mutex_lock_file | ||
|
||
with open(lock_file_path, 'w') as lock_file: | ||
try: | ||
# Try to acquire the lock | ||
fcntl.flock(lock_file, fcntl.LOCK_EX) | ||
|
||
# Call the actual function | ||
result = func(self, *args, **kwargs) | ||
finally: | ||
# Always release the lock | ||
fcntl.flock(lock_file, fcntl.LOCK_UN) | ||
|
||
return result | ||
|
||
return wrapper | ||
|
||
return decorator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters