-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #368 from sanger/DPL-034-wrap-crawler-in-flask
Dpl 034 wrap crawler in flask
- Loading branch information
Showing
17 changed files
with
422 additions
and
220 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# use publicly acessible env variables in this file | ||
# https://flask.palletsprojects.com/en/1.1.x/cli/#environment-variables-from-dotenv | ||
|
||
# https://flask.palletsprojects.com/en/1.1.x/cli/#application-discovery | ||
FLASK_APP=crawler | ||
|
||
# https://flask.palletsprojects.com/en/1.1.x/cli/#setting-command-options | ||
FLASK_RUN_HOST=0.0.0.0 | ||
FLASK_RUN_PORT=8000 | ||
|
||
# https://flask.palletsprojects.com/en/1.1.x/config/#environment-and-debug-features | ||
FLASK_ENV=development | ||
|
||
SETTINGS_MODULE=crawler.config.development |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.17.0 | ||
1.18.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from http import HTTPStatus | ||
import logging | ||
import logging.config | ||
import os | ||
|
||
from flask import Flask | ||
from flask_apscheduler import APScheduler | ||
|
||
from crawler.constants import SCHEDULER_JOB_ID_RUN_CRAWLER | ||
|
||
scheduler = APScheduler() | ||
|
||
|
||
def create_app() -> Flask: | ||
app = Flask(__name__) | ||
app.config.from_object(os.environ["SETTINGS_MODULE"]) | ||
|
||
# setup logging | ||
logging.config.dictConfig(app.config["LOGGING"]) | ||
|
||
if app.config.get("SCHEDULER_RUN", False): | ||
scheduler.init_app(app) | ||
scheduler.start() | ||
|
||
@app.get("/health") | ||
def health_check(): | ||
if scheduler.get_job(SCHEDULER_JOB_ID_RUN_CRAWLER): | ||
return "Crawler is working", HTTPStatus.OK | ||
|
||
return "Crawler is not working correctly", HTTPStatus.INTERNAL_SERVER_ERROR | ||
|
||
return app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from flask import current_app as app | ||
import logging | ||
|
||
from crawler import scheduler | ||
from crawler.helpers.general_helpers import get_config | ||
from crawler.main import run | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def scheduled_run(): | ||
"""Scheduler's job to do a run every 30 minutes.""" | ||
config, _ = get_config() | ||
logging.config.dictConfig(config.LOGGING) | ||
|
||
logger.info("Starting scheduled_run job.") | ||
|
||
with scheduler.app.app_context(): | ||
use_sftp = app.config["USE_SFTP"] | ||
keep_files = app.config["KEEP_FILES"] | ||
add_to_dart = app.config["ADD_TO_DART"] | ||
run(use_sftp, keep_files, add_to_dart) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters