'Perform database cleanup if cleanup interval has been met.
Fires events:
* manager.db_cleanup
If interval was met. Gives session to do the cleanup as a parameter.
:param bool force: Run the cleanup no matter whether the interval has been met.'

def db_cleanup(self, force=False):

    expired = (self.persist.get(u'last_cleanup', datetime(1900, 1, 1)) < (datetime.now() - DB_CLEANUP_INTERVAL))
    if (force or expired):
        log.info(u'Running    database    cleanup.')
        with Session() as session:
            fire_event(u'manager.db_cleanup', self, session)
        self.config_changed()
        self.persist[u'last_cleanup'] = datetime.now()
    else:
        log.debug((u'Not    running    db    cleanup,    last    run    %s' % self.persist.get(u'last_cleanup')))
