-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcluster_lock.py
More file actions
42 lines (34 loc) · 1.19 KB
/
cluster_lock.py
File metadata and controls
42 lines (34 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import time
from django.core.management.base import BaseCommand
from django.core.cache import cache
from django.conf import settings
lock_key = "drycc:controller:version"
waitting_init_msg = "version inconsistency %s!=%s, waiting for initialization to complete..."
class Command(BaseCommand):
"""Management command for push data to manager"""
def add_arguments(self, parser):
parser.add_argument(
"args",
metavar="action",
nargs="+",
choices=["lock", "unlock", "waitting"],
help="an action that needs to be executed.",
)
def lock(self):
cache.delete(lock_key)
print("lock completed!")
def unlock(self):
cache.set(lock_key, settings.VERSION, timeout=None)
print("unlock completed!")
def waitting(self):
while True:
version = cache.get(lock_key, None)
if version != settings.VERSION:
print(waitting_init_msg % (version, settings.VERSION))
else:
break
time.sleep(10)
print("waiting completed!")
def handle(self, *args, **options):
action = args[0]
getattr(self, action)()