-
Notifications
You must be signed in to change notification settings - Fork 1
/
tasks.py
executable file
·45 lines (34 loc) · 1 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
"""Initial tasks to be invoked after containers up.
Tasks are defined with ``invoke`` package.
See details at http://www.pyinvoke.org/.
"""
import os
import time
from invoke import task
def wait_port_is_open(host, port):
import socket
while True:
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
result = sock.connect_ex((host, port))
sock.close()
if result == 0:
return
except socket.gaierror:
pass
time.sleep(1)
@task
def init_db(ctx):
wait_port_is_open(os.getenv('DB_HOST', 'db'), 5432)
ctx.run('python sandbox/manage.py makemigrations')
ctx.run('python sandbox/manage.py migrate')
@task
def start_celery(ctx):
ctx.run('cp /code/celery.conf /etc/supervisor/conf.d/ && '
'service supervisor start && '
'supervisorctl start celery')
@task
def run(ctx):
init_db(ctx)
start_celery(ctx)
ctx.run('python sandbox/manage.py runserver 0.0.0.0:8990')