Revision e63050ca
b/snf-cyclades-app/synnefo/logic/reconciliation.py | ||
---|---|---|
79 | 79 |
|
80 | 80 |
log = logging.getLogger() |
81 | 81 |
|
82 |
try: |
|
83 |
CHECK_INTERVAL = settings.RECONCILIATION_CHECK_INTERVAL |
|
84 |
except AttributeError: |
|
85 |
CHECK_INTERVAL = 60 |
|
86 |
|
|
87 |
|
|
88 |
def needs_reconciliation(vm): |
|
89 |
now = datetime.now() |
|
90 |
return (now > vm.updated + timedelta(seconds=CHECK_INTERVAL)) or\ |
|
91 |
(now > vm.backendtime + timedelta(seconds=2*CHECK_INTERVAL)) |
|
92 |
|
|
82 | 93 |
|
83 | 94 |
def stale_servers_in_db(D, G): |
84 | 95 |
idD = set(D.keys()) |
... | ... | |
88 | 99 |
for i in idD - idG: |
89 | 100 |
if D[i] == 'BUILD': |
90 | 101 |
vm = VirtualMachine.objects.get(id=i) |
91 |
# Check time to avoid many rapi calls |
|
92 |
if datetime.now() > vm.backendtime + timedelta(seconds=5): |
|
102 |
if needs_reconciliation(vm): |
|
93 | 103 |
with pooled_rapi_client(vm) as c: |
94 | 104 |
try: |
95 | 105 |
job_status = c.GetJobStatus(vm.backendjobid)['status'] |
... | ... | |
127 | 137 |
unsynced.add((i, D[i], G[i])) |
128 | 138 |
if not G[i] and D[i] == 'BUILD': |
129 | 139 |
vm = VirtualMachine.objects.get(id=i) |
130 |
# Check time to avoid many rapi calls |
|
131 |
if datetime.now() > vm.backendtime + timedelta(seconds=5): |
|
140 |
if needs_reconciliation(vm): |
|
132 | 141 |
with pooled_rapi_client(vm) as c: |
133 | 142 |
try: |
134 | 143 |
job_info = c.GetJobStatus(job_id=vm.backendjobid) |
... | ... | |
153 | 162 |
# If a job has not been enqueued after 2 minutues, then |
154 | 163 |
# it must be a stale entry.. |
155 | 164 |
failed.add(i) |
156 |
elif datetime.now() > vm.backendtime + timedelta(seconds=30):
|
|
165 |
elif needs_reconciliation(vm):
|
|
157 | 166 |
# Check time to avoid many rapi calls |
158 | 167 |
with pooled_rapi_client(vm) as c: |
159 | 168 |
try: |
Also available in: Unified diff