def main(): init_logging() init_model(config.SQLALCHEMY_URL) shutdown_event = threading.Event() scheduler = BackgroundScheduler() # workflow_publisher = configured_publisher() activity_sync = ActivitySync() weather_sync = WeatherSync() athlete_sync = AthleteSync() # Every hour run a sync on the activities for athletes fall into the specified segment # athlete_id % total_segments == segment # TODO: Probably it would be more prudent to split into 15-minute segments, to match rate limits # Admittedly that will make the time-based segment calculation a little trickier. def segmented_sync_activities(): activity_sync.sync_rides_distributed(total_segments=4, segment=(arrow.now().hour % 4)) scheduler.add_job(segmented_sync_activities, 'cron', minute='50') # This should generally not pick up anytihng. scheduler.add_job(activity_sync.sync_rides_detail, 'cron', minute='20') # Sync weather at 8am UTC scheduler.add_job(weather_sync.sync_weather, 'cron', hour='8') # Sync athletes once a day at 6am UTC scheduler.add_job(athlete_sync.sync_athletes, 'cron', minute='30') scheduler.start() beanclient = Client(host=config.BEANSTALKD_HOST, port=config.BEANSTALKD_PORT, watch=[DefinedTubes.activity_update.value]) subscriber = ActivityUpdateSubscriber(beanstalk_client=beanclient, shutdown_event=shutdown_event) def shutdown_app(): shutdown_event.wait() scheduler.shutdown() shutdown_monitor = threading.Thread(target=shutdown_app) shutdown_monitor.start() try: # This is here to simulate application activity (which keeps the main thread alive). subscriber.run_forever() except (KeyboardInterrupt, SystemExit): log.info("Exiting on user request.") except: log.exception("Error running sync/listener.") finally: shutdown_event.set() shutdown_monitor.join()
def execute(self, options, args): if options.drop: app.logger.info("Dropping tables.") init_model(app.config['SQLALCHEMY_DATABASE_URI'], drop=options.drop) # Drop and re-add supplementary objects drop_supplemental_db_objects(meta.engine) create_supplemental_db_objects(meta.engine)
def run(self, argv=None): parser = self.build_parser() assert parser is not None, "{}.build_parser() method did not return a parser object.".format( self.__class__.__name__) args = parser.parse_args(argv) self.init_logging(args) init_model(sqlalchemy_url=config.SQLALCHEMY_URL) try: self.execute(args) except CommandError as ce: parser.error(str(ce)) raise SystemExit(127)
#from flask.ext.sqlalchemy import SQLAlchemy app = Flask(__name__, static_url_path='/assets') app.config.from_object('freezing.web.default_settings') if 'BAFS_SETTINGS' in os.environ: app.config.from_envvar('BAFS_SETTINGS') app.secret_key = app.config['SESSION_SECRET'] if not app.secret_key: raise RuntimeError( "Configuration error. No SESSION_SECRET configuration variable defined." ) from freezing.model import init_model init_model(app.config['SQLALCHEMY_DATABASE_URI']) # This needs to be after the app is created. from freezing.web.views import general, leaderboard, chartdata, people, user, pointless, photos, api, alt_scoring from freezing.web.utils import auth # Register our blueprints app.register_blueprint(general.blueprint) app.register_blueprint(leaderboard.blueprint, url_prefix='/leaderboard') app.register_blueprint(alt_scoring.blueprint, url_prefix='/alt_scoring') app.register_blueprint(chartdata.blueprint, url_prefix='/chartdata') app.register_blueprint(people.blueprint, url_prefix='/people') app.register_blueprint(pointless.blueprint, url_prefix='/pointless') app.register_blueprint(photos.blueprint, url_prefix='/photos') app.register_blueprint(user.blueprint, url_prefix='/my')
import os import os.path from flask import Flask, session, g from freezing.model import init_model, meta from .config import config # Thanks https://stackoverflow.com/a/17073583 app = Flask(__name__, static_folder='static', static_url_path='/') app.config.from_object(config) init_model(config.SQLALCHEMY_URL) # This needs to be after the app is created, unfortunately. from freezing.web.views import general, leaderboard, chartdata, people, user, pointless, photos, api, alt_scoring from freezing.web.utils import auth # Register our blueprints app.register_blueprint(general.blueprint) app.register_blueprint(leaderboard.blueprint, url_prefix='/leaderboard') app.register_blueprint(alt_scoring.blueprint, url_prefix='/alt_scoring') app.register_blueprint(chartdata.blueprint, url_prefix='/chartdata') app.register_blueprint(people.blueprint, url_prefix='/people') app.register_blueprint(pointless.blueprint, url_prefix='/pointless') app.register_blueprint(photos.blueprint, url_prefix='/photos') app.register_blueprint(user.blueprint, url_prefix='/my') app.register_blueprint(api.blueprint, url_prefix='/api')
import os import os.path from flask import Flask, session, g from freezing.model import init_model, meta from .config import config app = Flask(__name__, static_url_path='/assets') app.config.from_object(config) init_model(config.SQLALCHEMY_URL) # This needs to be after the app is created, unfortunately. from freezing.web.views import general, leaderboard, chartdata, people, user, pointless, photos, api, alt_scoring from freezing.web.utils import auth # Register our blueprints app.register_blueprint(general.blueprint) app.register_blueprint(leaderboard.blueprint, url_prefix='/leaderboard') app.register_blueprint(alt_scoring.blueprint, url_prefix='/alt_scoring') app.register_blueprint(chartdata.blueprint, url_prefix='/chartdata') app.register_blueprint(people.blueprint, url_prefix='/people') app.register_blueprint(pointless.blueprint, url_prefix='/pointless') app.register_blueprint(photos.blueprint, url_prefix='/photos') app.register_blueprint(user.blueprint, url_prefix='/my') app.register_blueprint(api.blueprint, url_prefix='/api') @app.before_request