"""Feed Status Monitoring API.""" import logging import boto3 from flask import Flask from flask import render_template from flask import Response from flask_restful import Api import sentry_sdk from sentry_sdk.integrations.flask import FlaskIntegration from sentry_sdk.integrations.logging import LoggingIntegration from feed_status import config from feed_status.resources import activity_detector_feeds from feed_status.resources import delphi_feeds # from feed_status.resources import feeds_units from feed_status.resources import health from feed_status.resources import ingestion_feeds from feed_status.resources import outgoing_feeds from feed_status.resources import service_links from feed_status.resources import snowflake_sync app = Flask(__name__) sentry_logging = LoggingIntegration( level=logging.ERROR, event_level=logging.ERROR) if config.SENTRY_DSN: sentry_sdk.init( dsn=config.SENTRY_DSN, integrations=[FlaskIntegration(), sentry_logging], # TODO: expose SENTRY_RELEASE during dockerbuild # By default the SDK will try to use the SENTRY_RELEASE # environment variable, or infer a git commit # SHA as release, however you may want to set # something more human-readable. # release="myapp@1.0.0", release='monty@2.1.1') @app.route('/') def index(): """Show monty2.1 dashboard.""" return render_template('index.html') @app.route('/delphi') def delphi(): """Show monty2.1 dashboard.""" return render_template('delphi.html') @app.route('/dbt/') def dbt_docs_from_s3(resource): """Resource: name of the file to proxy.""" s3 = boto3.client('s3', region_name=config.AWS_REGION) s3_object = s3.get_object( Bucket=config.S3_BUCKET_NAME, Key='dbt_docs/' + resource) return Response(s3_object['Body']) # scheduler = BackgroundScheduler(daemon=True) # for file in os.listdir('feed_status/connectors/queries'): # feed_id = file.replace('_units.sql', '') # licensors = ['sme', 'theorchard'] # for licensor in licensors: # scheduler.add_job(feeds_units.FeedUnits.get, 'interval', minutes=60, # args=[feeds_units.FeedUnits(), feed_id, licensor]) # scheduler.add_job(feeds_units.AllFeedsUnits.get, 'interval', # minutes=60, args=[feeds_units.AllFeedsUnits()]) # scheduler.start() api = Api(app) api.add_resource(health.HealthCheck, '/health') api.add_resource( activity_detector_feeds.ActivityDetectorFeedStatus, '/activity_detector_feed//status', '/activity_detector_feed//status/', ) api.add_resource( ingestion_feeds.MarketshareIngestionFeedStatus, '/marketshare_feeds/status', '/marketshare_feeds/status/', ) api.add_resource( ingestion_feeds.MonthlyIngestionFeedStatus, '/monthly_feeds/status', '/monthly_feeds/status/', ) api.add_resource(ingestion_feeds.IngestionFeedStatus, '/ingestion_feed//status', '/ingestion_feed//status/') api.add_resource(outgoing_feeds.OutgoingFeedStatus, '/outgoing_feed//status', '/outgoing_feed//status/') api.add_resource(snowflake_sync.SnowflakeSync, '/snowflake_sync//status') api.add_resource(delphi_feeds.DelphiFeedStatus, '/delphi_feed//status', '/delphi_feed//status/') api.add_resource(ingestion_feeds.IngestionFeedComment, '/ingestion_feed/comment//') api.add_resource(ingestion_feeds.IngestionFeedCommentList, '/ingestion_feed/comment_list') # todo: add FastAPI and move to its own routes api.add_resource(service_links.ServiceLinks, '/ingestion_feed/service_links') # api.add_resource(feeds_units.FeedUnits, # '/feed_units//') # # api.add_resource(feeds_units.AllFeedsUnits, # '/all_feeds_units') if __name__ == '__main__': app.run(host='0.0.0.0', port=5000, debug=False)