Created
November 8, 2017 16:43
-
-
Save blaggacao/45df324285872eac53b34ef561921a76 to your computer and use it in GitHub Desktop.
Maintenance Worker
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
class WorkerMaintenance(WorkerCron): | |
def __init__(self, multi): | |
super(WorkerMaintenance, self).__init__(multi) | |
self.watchdog_timeout = multi.maintenance_timeout | |
def process_work(self): | |
rpc_request = logging.getLogger('odoo.netsvc.rpc.request') | |
rpc_request_flag = rpc_request.isEnabledFor(logging.DEBUG) | |
_logger.debug("WorkerMaintenance (%s) polling for install/updates", self.pid) | |
db_names = self._db_list() | |
if len(db_names): | |
self.db_index = (self.db_index + 1) % len(db_names) | |
db_name = db_names[self.db_index] | |
self.setproctitle(db_name) | |
if rpc_request_flag: | |
start_time = time.time() | |
start_rss, start_vms = memory_info(psutil.Process(os.getpid())) | |
import odoo.addons.base as base | |
base.ir.ir_maintenance.IrMaintenance._acquire_job(db_name, self.db_index) | |
odoo.modules.registry.Registry.delete(db_name) | |
# dont keep cursors in multi database mode | |
if len(db_names) > 1: | |
odoo.sql_db.close_db(db_name) | |
if rpc_request_flag: | |
run_time = time.time() - start_time | |
end_rss, end_vms = memory_info(psutil.Process(os.getpid())) | |
vms_diff = (end_vms - start_vms) / 1024 | |
logline = '%s time:%.3fs mem: %sk -> %sk (diff: %sk)' % \ | |
(db_name, run_time, start_vms / 1024, end_vms / 1024, vms_diff) | |
_logger.debug("WorkerMaintenance (%s) %s", self.pid, logline) | |
self.request_count += 1 | |
if self.request_count >= self.request_max and self.request_max < len(db_names): | |
_logger.error("There are more dabatases to process than allowed " | |
"by the `limit_request` configuration variable: %s more.", | |
len(db_names) - self.request_max) | |
else: | |
self.db_index = 0 | |
def start(self): | |
os.nice(15) # Prioritize after cron workers | |
Worker.start(self) | |
if self.multi.socket: | |
self.multi.socket.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment