From 5151b8e217ee03a5cedca4b96b590815378797c2 Mon Sep 17 00:00:00 2001 From: crflynn Date: Sat, 28 Apr 2018 23:22:29 -0400 Subject: [PATCH] add gunicorn server; supervisord to stdout --- Dockerfile | 2 -- Pipfile | 1 + Pipfile.lock | 9 ++++++++- pypistats/settings.py | 2 +- pypistats/tasks/pypi.py | 3 ++- scripts/run_flask.sh | 3 ++- supervisord.conf | 25 ++++++++++++++++--------- 7 files changed, 30 insertions(+), 15 deletions(-) diff --git a/Dockerfile b/Dockerfile index f8786f6..1604fe2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,8 +4,6 @@ RUN pip install pipenv ENV WORKON_HOME=/venv -RUN mkdir /var/log/pypistats - WORKDIR /app ADD Pipfile /app diff --git a/Pipfile b/Pipfile index 26071d0..5ce5438 100644 --- a/Pipfile +++ b/Pipfile @@ -18,6 +18,7 @@ flask-wtf = "*" celery = "*" redis = "*" flask-sslify = "*" +gunicorn = "*" [dev-packages] diff --git a/Pipfile.lock b/Pipfile.lock index 324a23d..35a3dd4 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "2abcd9e93501a30aca9909ec9bca5c2478d21efcc2fde03db74701e6d10a02ca" + "sha256": "3326ede3fc3848d6990929fd0167ac93cfaeba00ab4564ee13948dfb2429264c" }, "host-environment-markers": { "implementation_name": "cpython", @@ -169,6 +169,13 @@ ], "version": "==1.5.3" }, + "gunicorn": { + "hashes": [ + "sha256:f5ca088d029fe3cea166c59bb43b7ccc9c850fe25af3da61350fe712c5cc5aa2", + "sha256:eb8d8924b117a609fae9f8cd85df0cad3535dd613fdbcdbba3ee88d5459f1d4f" + ], + "version": "==19.8.0" + }, "idna": { "hashes": [ "sha256:8c7309c718f94b3a625cb648ace320157ad16ff131ae0af362c9f21b80ef6ec4", diff --git a/pypistats/settings.py b/pypistats/settings.py index fa1cab7..190f12f 100644 --- a/pypistats/settings.py +++ b/pypistats/settings.py @@ -25,7 +25,7 @@ class Config(object): CELERYBEAT_SCHEDULE = { "update_db": { "task": "pypistats.tasks.pypi.etl", - "schedule": crontab(hour=1, minute=0), # 1am UTC + "schedule": crontab(minute=0, hour=1), # 1am UTC }, } GITHUB_CLIENT_ID = os.environ.get("GITHUB_CLIENT_ID") diff --git a/pypistats/tasks/pypi.py b/pypistats/tasks/pypi.py index a26f824..4ae8401 100644 --- a/pypistats/tasks/pypi.py +++ b/pypistats/tasks/pypi.py @@ -61,6 +61,7 @@ def get_daily_download_stats(env="dev", date=None): if date is None: date = str(datetime.date.today() - datetime.timedelta(days=1)) + print(date) print("Sending query to BigQuery...") query = get_query(date) print("Sent.") @@ -374,7 +375,7 @@ def etl(): if __name__ == "__main__": - date = "2018-04-27" + date = "2018-04-28" env = "prod" print(date, env) print(get_daily_download_stats(env, date)) diff --git a/scripts/run_flask.sh b/scripts/run_flask.sh index 7af0fb7..387bc42 100755 --- a/scripts/run_flask.sh +++ b/scripts/run_flask.sh @@ -2,4 +2,5 @@ export ENV=prod set -o allexport source pypistats/secret/$ENV.env set +o allexport -pipenv run flask run --host=0.0.0.0 +# pipenv run flask run --host=0.0.0.0 +pipenv run gunicorn -b 0.0.0.0:5000 -w 4 --access-logfile - --error-log - pypistats.run:app diff --git a/supervisord.conf b/supervisord.conf index 68067bc..a2809f2 100644 --- a/supervisord.conf +++ b/supervisord.conf @@ -1,24 +1,31 @@ [supervisord] nodaemon=true -logfile=/var/log/pypistats/supervisord.log [program:redis] -stdout_logfile=/var/log/pypistats/redis.log -stderr_logfile=/var/log/pypistats/redis.err +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stdout +stderr_logfile_maxbytes=0 command=redis-server [program:pypistats] -stdout_logfile=/var/log/pypistats/pypistats.log -stderr_logfile=/var/log/pypistats/pypistats.err +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stdout +stderr_logfile_maxbytes=0 command=bash -c "scripts/run_flask.sh" [program:celery-worker] -stdout_logfile=/var/log/pypistats/celery-worker.log -stderr_logfile=/var/log/pypistats/celery-worker.err +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stdout +stderr_logfile_maxbytes=0 user=nobody command=bash -c "scripts/run_celery.sh" [program:celery-beat] -stdout_logfile=/var/log/pypistats/celery-beat.log -stderr_logfile=/var/log/pypistats/celery-beat.err +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +stderr_logfile=/dev/stdout +stderr_logfile_maxbytes=0 command=bash -c "scripts/run_beat.sh"