# Path: networking_odl/db/db.py
# LOG = logging.getLogger(__name__)
# def get_pending_or_processing_ops(context, object_uuid, operation=None):
# def get_pending_delete_ops_with_parent(context, object_type, parent_id):
# def get_all_db_rows(context):
# def get_all_db_rows_by_state(context, state):
# def get_oldest_pending_db_row_with_lock(context):
# def delete_dependency(context, entry):
# def update_db_row_state(context, row, state, flush=True):
# def update_pending_db_row_retry(context, row, retry_count):
# def delete_row(context, row=None, row_id=None, flush=True):
# def create_pending_row(context, object_type, object_uuid,
#                        operation, data, depending_on=None):
# def delete_pending_rows(context, operations_to_delete):
# def _update_periodic_task_state(context, expected_state, state, task):
# def was_periodic_task_executed_recently(context, task, interval):
# def lock_periodic_task(context, task):
# def unlock_periodic_task(context, task):
# def update_periodic_task(context, task, operation=None):
# def delete_rows_by_state_and_time(context, state, time_delta):
# def reset_processing_rows(context, max_timedelta):


from neutron_lib import context as neutron_context
from neutron_lib.db import api as db_api
from oslo_log import log as logging
from oslo_service import loopingcall
from networking_odl.db import db




LOG = logging.getLogger(__name__)


class PeriodicTask(object):
    def __init__(self, task, interval):
        self.task = task
        self.phases = []
        self.timer = loopingcall.FixedIntervalLoopingCall(self.execute_ops)
        self.interval = interval

    def start(self):
        self.timer.start(self.interval, stop_on_exception=False)

    def cleanup(self):
        # this method is used for unit test to tear down
        self.timer.stop()
        try:
            self.timer.wait()
        except AttributeError:
            # NOTE(yamahata): workaround
            # some tests call this cleanup without calling start
            pass

    @db_api.retry_if_session_inactive()
    @db_api.CONTEXT_WRITER.savepoint
    def _set_operation(self, context, operation):

# Path: networking_odl/db/db.py
# LOG = logging.getLogger(__name__)
# def get_pending_or_processing_ops(context, object_uuid, operation=None):
# def get_pending_delete_ops_with_parent(context, object_type, parent_id):
# def get_all_db_rows(context):
# def get_all_db_rows_by_state(context, state):
# def get_oldest_pending_db_row_with_lock(context):
# def delete_dependency(context, entry):
# def update_db_row_state(context, row, state, flush=True):
# def update_pending_db_row_retry(context, row, retry_count):
# def delete_row(context, row=None, row_id=None, flush=True):
# def create_pending_row(context, object_type, object_uuid,
#                        operation, data, depending_on=None):
# def delete_pending_rows(context, operations_to_delete):
# def _update_periodic_task_state(context, expected_state, state, task):
# def was_periodic_task_executed_recently(context, task, interval):
# def lock_periodic_task(context, task):
# def unlock_periodic_task(context, task):
# def update_periodic_task(context, task, operation=None):
# def delete_rows_by_state_and_time(context, state, time_delta):
# def reset_processing_rows(context, max_timedelta):


# Path: networking_odl/journal/periodic_task.py
from neutron_lib import context as neutron_context
from neutron_lib.db import api as db_api
from oslo_log import log as logging
from oslo_service import loopingcall
from networking_odl.db import db





LOG = logging.getLogger(__name__)


class PeriodicTask(object):
    def __init__(self, task, interval):
        self.task = task
        self.phases = []
        self.timer = loopingcall.FixedIntervalLoopingCall(self.execute_ops)
        self.interval = interval

    def start(self):
        self.timer.start(self.interval, stop_on_exception=False)

    def cleanup(self):
        # this method is used for unit test to tear down
        self.timer.stop()
        try:
            self.timer.wait()
        except AttributeError:
            # NOTE(yamahata): workaround
            # some tests call this cleanup without calling start
            pass

    @db_api.retry_if_session_inactive()
    @db_api.CONTEXT_WRITER.savepoint
    def _set_operation(self, context, operation):

        db.update_periodic_task(context, task=self.task,