add gunicorn server; supervisord to stdout

This commit is contained in:
crflynn
2018-04-28 23:22:29 -04:00
parent e665b09909
commit 5151b8e217
7 changed files with 30 additions and 15 deletions

View File

@@ -4,8 +4,6 @@ RUN pip install pipenv
ENV WORKON_HOME=/venv
RUN mkdir /var/log/pypistats
WORKDIR /app
ADD Pipfile /app

View File

@@ -18,6 +18,7 @@ flask-wtf = "*"
celery = "*"
redis = "*"
flask-sslify = "*"
gunicorn = "*"
[dev-packages]

9
Pipfile.lock generated
View File

@@ -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",

View File

@@ -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")

View File

@@ -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))

View File

@@ -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

View File

@@ -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"