def flush_runs(): APP = App.get_app() retention_days = int(APP.config['GHC_RETENTION_DAYS']) LOGGER.info('Flushing runs older than %d days' % retention_days) all_runs = Run.query.all() run_count = 0 for run in all_runs: days_old = (datetime.utcnow() - run.checked_datetime).days if days_old > retention_days: run_count += 1 DB.session.delete(run) db_commit() LOGGER.info('Deleted %d Runs' % run_count) DB.session.remove()
from flask_babel import gettext from flask_login import (LoginManager, login_user, logout_user, current_user, login_required) from flask_migrate import Migrate from __init__ import __version__ from init import App from enums import RESOURCE_TYPES from models import Resource, Run, ProbeVars, CheckVars, Tag, User, Recipient from factory import Factory from util import send_email, geocode import views # Module globals for convenience LOGGER = logging.getLogger(__name__) APP = App.get_app() CONFIG = App.get_config() DB = App.get_db() BABEL = App.get_babel() MIGRATE = Migrate(APP, DB) LOGIN_MANAGER = LoginManager() LOGIN_MANAGER.init_app(APP) LANGUAGES = (('en', 'English'), ('fr', 'Français'), ('de', 'German'), ('de_DE', 'German (Germany)'), ('nl_NL', 'Nederlands (Nederland)'), ('es_BO', 'Español (Bolivia)'), ('hr_HR', 'Croatian (Croatia)')) # Should GHC Runner be run within GHC webapp?
from owslib.tms import TileMapService from owslib.wfs import WebFeatureService from owslib.wcs import WebCoverageService from owslib.wps import WebProcessingService from owslib.csw import CatalogueServiceWeb from owslib.sos import SensorObservationService from init import App from enums import RESOURCE_TYPES from models import Resource, Run from probe import Probe from result import ResourceResult from notifications import notify LOGGER = logging.getLogger(__name__) APP = App.get_app() DB = App.get_db() # commit or rollback shorthand def db_commit(): err = None try: DB.session.commit() except Exception as err: DB.session.rollback() # finally: # DB.session.close() return err