-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtasks.py
70 lines (54 loc) · 1.87 KB
/
tasks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import os
from time import sleep
from invoke import task, exceptions
from django.conf import settings
DB_ARGS = f"-h {settings.DATABASES['default']['HOST']}" \
f" -U {settings.DATABASES['default']['USER']}" \
f" -p {settings.DATABASES['default']['PORT']}"
@task
def waitdb(ctx):
while True:
try:
ctx.run(f"PGPASSWORD={settings.DATABASES['default']['PASSWORD']} psql {DB_ARGS} -c '\\l'")
return
except exceptions.Failure:
print('err')
sleep(5)
@task
def dropdb(ctx):
waitdb(ctx)
ctx.run(f"PGPASSWORD={settings.DATABASES['default']['PASSWORD']} dropdb {DB_ARGS} movies")
@task
def createdb(ctx):
waitdb(ctx)
ctx.run(f"PGPASSWORD={settings.DATABASES['default']['PASSWORD']} createdb {DB_ARGS} movies")
@task
def makedump(ctx):
waitdb(ctx)
ctx.run(f"PGPASSWORD={settings.DATABASES['default']['PASSWORD']} pg_dump {DB_ARGS} {settings.DATABASES['default']['NAME']} > dump.sql")
@task
def loaddump(ctx):
dropdb(ctx)
createdb(ctx)
ctx.run(f"PGPASSWORD={settings.DATABASES['default']['PASSWORD']} psql {DB_ARGS} {settings.DATABASES['default']['NAME']} < dump.sql")
@task
def run(ctx):
print('Migrating db')
ctx.run('./manage.py migrate')
print('Collecting static')
ctx.run('./manage.py collectstatic --noinput')
cmd = ('uwsgi --http 0.0.0.0:8000 --master '
'--module "django.core.wsgi:get_wsgi_application()" '
'--processes 2 '
'--offload-threads 4 '
'--enable-threads '
'--static-map /static=/static')
if os.getenv('PY_AUTORELOAD'):
cmd += ' --py-autoreload 1'
if os.getenv('BASICAUTH'):
cmd += ' --route "^/ basicauth:SR,{0}"'.format(os.getenv('BASICAUTH'))
if os.getenv('ENV') == 'dev':
cmd += ' --honour-stdin'
else:
cmd += ' --harakiri 30'
ctx.run(cmd)