Repository :
http://git.fedorahosted.org/cgit/copr.git
On branch : master
---------------------------------------------------------------
commit 3ae99137727e8a6173fe4f8ef393c5ec3c7ff997
Author: Valentin Gologuzov <vgologuz(a)redhat.com>
Date: Fri Apr 24 14:24:15 2015 +0200
[backend] small cleanup, need more tests
---------------------------------------------------------------
backend/backend/daemons/dispatcher.py | 8 +++++---
backend/backend/vm_manage/event_handle.py | 4 ++--
2 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/backend/backend/daemons/dispatcher.py
b/backend/backend/daemons/dispatcher.py
index 8897aa8..66d1af8 100644
--- a/backend/backend/daemons/dispatcher.py
+++ b/backend/backend/daemons/dispatcher.py
@@ -386,6 +386,8 @@ class Worker(multiprocessing.Process):
self.rc.publish(JOB_GRAB_TASK_END_PUBSUB, json.dumps(request))
def acquire_vm_for_job(self, job):
+ # TODO: replace acquire/release with context manager
+
self.log.info("got job: {}, acquiring VM for build".format(str(job)))
start_vm_wait_time = time.time()
vmd = None
@@ -401,8 +403,6 @@ class Worker(multiprocessing.Process):
continue
except Exception as error:
self.log.exception("Unhandled exception during VM acquire
:{}".format(error))
- self.notify_job_grab_about_task_end(job, do_reschedule=True)
- time.sleep(self.opts.sleeptime)
break
return vmd
@@ -420,7 +420,9 @@ class Worker(multiprocessing.Process):
vmd = self.acquire_vm_for_job(job)
- if vmd is not None:
+ if vmd is None:
+ self.notify_job_grab_about_task_end(job, do_reschedule=True)
+ else:
self.log.info("acquired VM: {} ip: {} for build
{}".format(vmd.vm_name, vmd.vm_ip, job.task_id))
# TODO: store self.vmd = vmd and use it
self.vm_name = vmd.vm_name
diff --git a/backend/backend/vm_manage/event_handle.py
b/backend/backend/vm_manage/event_handle.py
index c12076f..8c0b328 100644
--- a/backend/backend/vm_manage/event_handle.py
+++ b/backend/backend/vm_manage/event_handle.py
@@ -103,8 +103,8 @@ class EventHandler(Process):
else:
self.log.debug("recording check fail: {}".format(msg))
self.lua_scripts["record_failure"](keys=[vmd.vm_key])
- too_much_fails = int(vmd.get_field(self.vmm.rc, "check_fails") or
0) > Thresholds.max_check_fails
- if too_much_fails and vmd.state != VmStates.IN_USE:
+ fails_count = int(vmd.get_field(self.vmm.rc, "check_fails") or 0)
+ if fails_count > Thresholds.max_check_fails and vmd.state !=
VmStates.IN_USE:
self.log.info("check fail threshold reached: {}, terminating:
{}"
.format(check_fails_count, msg))
self.vmm.start_vm_termination(vmd.vm_name)