def execute_ops(self): LOG.info("Starting %s periodic task.", self.task) context = neutron_context.get_admin_context() # Lock make sure that periodic task is executed only after # specified interval. It makes sure that maintenance tasks # are not executed back to back. if self.task_already_executed_recently(context): LOG.info( "Periodic %s task executed after periodic interval " "Skipping execution.", self.task) return if not db.lock_periodic_task(context.session, self.task): LOG.info("Periodic %s task already running task", self.task) return try: for phase in self.phases: self._execute_op(phase, context) finally: db.update_periodic_task(context.session, task=self.task, operation=None) db.unlock_periodic_task(context.session, self.task) LOG.info("%s task has been finished", self.task)
def _execute_op(self, operation, context): op_details = operation.__name__ if operation.__doc__: op_details += " (%s)" % operation.func_doc try: LOG.info("Starting %s phase of periodic task %s.", op_details, self.task) db.update_periodic_task(context.session, task=self.task, operation=operation) operation(context=context) LOG.info("Finished %s phase of %s task.", op_details, self.task) except Exception: LOG.exception("Failed during periodic task operation %s.", op_details)
def _clear_and_unlock_task(self, context): session = context.session with db_api.autonested_transaction(session): db.update_periodic_task(session, task=self.task, operation=None) db.unlock_periodic_task(session, self.task)
def _set_operation(self, context, operation): session = context.session with db_api.autonested_transaction(session): db.update_periodic_task(session, task=self.task, operation=operation)
def _clear_and_unlock_task(self, context): db.update_periodic_task(context, task=self.task, operation=None) db.unlock_periodic_task(context, self.task)
def _set_operation(self, context, operation): db.update_periodic_task(context, task=self.task, operation=operation)
def _clear_and_unlock_task(self, context): db.update_periodic_task(context, task=self.task, operation=None) db.unlock_periodic_task(context, self.task)
def _set_operation(self, context, operation): db.update_periodic_task(context, task=self.task, operation=operation)