- if ro_task["target_id"] not in self.engine.assignment_list:
- self.engine.assign_vim(ro_task["target_id"])
- self.logger.debug("ordered to load {}. Inactivity detected".format(ro_task["target_id"]))
-
- await asyncio.sleep(300, loop=self.loop)
+ # if already checked ignore
+ if ro_task["target_id"] in processed_vims:
+ continue
+ processed_vims.append(ro_task["target_id"])
+ # if already assigned ignore
+ if ro_task["target_id"] in self.engine.get_assigned_vims():
+ continue
+ # if there is some task locked on this VIM, there is an RO working on it, so ignore
+ if self.db.get_list("ro_tasks",
+ q_filter={"target_id": ro_task["target_id"],
+ "tasks.status": ['SCHEDULED', 'BUILD', 'DONE', 'FAILED'],
+ "locked_at.gt": now - self.MAX_TIME_LOCKED}):
+ continue
+ # unattended, assign vim
+ self.engine.assign_vim(ro_task["target_id"])
+ self.logger.debug("ordered to load {}. Inactivity detected".format(ro_task["target_id"]))
+
+ # every 2 hours check if there are vims without any ro_task and unload it
+ if now > self.next_check_unused_vim:
+ self.next_check_unused_vim = now + self.TIME_CHECK_UNUSED_VIM
+ self.engine.unload_unused_vims()
+ await asyncio.sleep(self.MAX_TIME_UNATTENDED, loop=self.loop)