Skip to content

Commit d71949f

Browse files
authored
Merge pull request #458 from mapswipe/separate-docker-containers
split workers into two separate docker containers
2 parents 3fa3049 + ff74b7f commit d71949f

File tree

5 files changed

+75
-11
lines changed

5 files changed

+75
-11
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ script:
3535
- isort --check --settings-file mapswipe_workers/setup.cfg mapswipe_workers
3636
- docker-compose up --build --detach firebase_deploy
3737
- docker-compose up --build --detach postgres
38-
- docker-compose run mapswipe_workers python -m unittest discover --verbose --start-directory tests/unittests/
39-
- docker-compose run mapswipe_workers python -m unittest discover --verbose --start-directory tests/integration/
38+
- docker-compose run mapswipe_workers_creation python -m unittest discover --verbose --start-directory tests/unittests/
39+
- docker-compose run mapswipe_workers_creation python -m unittest discover --verbose --start-directory tests/integration/
4040

4141
after_success:
4242
# SSH setup to deploy to server after build.

ansible/playbook.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
dest: $HOME/python-mapswipe-workers
1010
version: dev
1111
- name: Rebuild Docker container.
12-
command: docker-compose build postgres firebase_deploy mapswipe_workers manager_dashboard nginx api
12+
command: docker-compose build postgres firebase_deploy mapswipe_workers_creation mapswipe_workers_stats manager_dashboard nginx api
1313
args:
1414
chdir: $HOME/python-mapswipe-workers
1515
- name: Restart Docker container.
16-
command: docker-compose up -d --force-recreate postgres firebase_deploy mapswipe_workers manager_dashboard nginx api
16+
command: docker-compose up -d --force-recreate postgres firebase_deploy mapswipe_workers_creation mapswipe_workers_stats manager_dashboard nginx api
1717
args:
1818
chdir: $HOME/python-mapswipe-workers

docker-compose.yaml

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,41 @@ services:
4949
networks:
5050
- manager_dashboard
5151

52-
mapswipe_workers:
52+
mapswipe_workers_creation:
53+
container_name: mapswipe_workers
54+
build:
55+
context: mapswipe_workers/
56+
environment:
57+
FIREBASE_DB: '${FIREBASE_DB}'
58+
FIREBASE_API_KEY: '${FIREBASE_API_KEY}'
59+
FIREBASE_TOKEN: '${FIREBASE_TOKEN}'
60+
GOOGLE_APPLICATION_CREDENTIALS: 'serviceAccountKey.json'
61+
POSTGRES_PASSWORD: '${POSTGRES_PASSWORD}'
62+
POSTGRES_USER: '${POSTGRES_USER}'
63+
POSTGRES_DB: '${POSTGRES_DB}'
64+
POSTGRES_HOST: 'postgres'
65+
POSTGRES_PORT: 5432
66+
PGDATA: '/var/lib/postgresql/mapswipe'
67+
IMAGE_BING_API_KEY: '${IMAGE_BING_API_KEY}'
68+
IMAGE_ESRI_API_KEY: '${IMAGE_ESRI_API_KEY}'
69+
IMAGE_ESRI_BETA_API_KEY: '${IMAGE_ESRI_BETA_API_KEY}'
70+
IMAGE_MAPBOX_API_KEY: '${IMAGE_MAPBOX_API_KEY}'
71+
IMAGE_MAXAR_PREMIUM_API_KEY: '${IMAGE_MAXAR_PREMIUM_API_KEY}'
72+
IMAGE_MAXAR_STANDARD_API_KEY: '${IMAGE_MAXAR_STANDARD_API_KEY}'
73+
SLACK_TOKEN: '${SLACK_TOKEN}'
74+
SLACK_CHANNEL: '${SLACK_CHANNEL}'
75+
SENTRY_DSN: '${SENTRY_DSN}'
76+
depends_on:
77+
- postgres
78+
command: mapswipe_workers --verbose run --analysis_type=creation --schedule
79+
volumes:
80+
- ./mapswipe-data:/root/.local/share/mapswipe_workers
81+
restart: "no"
82+
networks:
83+
- mapswipe_workers
84+
- postgres
85+
86+
mapswipe_workers_stats:
5387
container_name: mapswipe_workers
5488
build:
5589
context: mapswipe_workers/
@@ -75,7 +109,7 @@ services:
75109
SENTRY_DSN: '${SENTRY_DSN}'
76110
depends_on:
77111
- postgres
78-
command: mapswipe_workers --verbose run --schedule
112+
command: mapswipe_workers --verbose run --analysis_type=stats --schedule
79113
volumes:
80114
- ./mapswipe-data:/root/.local/share/mapswipe_workers
81115
restart: "no"

mapswipe_workers/mapswipe_workers/mapswipe_workers.py

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,9 +383,19 @@ def run_delete_project(project_id, project_ids):
383383

384384

385385
@cli.command("run")
386+
@click.option(
387+
"--analysis_type",
388+
"-a",
389+
default="all",
390+
help=(
391+
f"Will either execute all or just the specified functions of the analysis "
392+
f"choices here"
393+
),
394+
type=click.Choice(["all", "creation", "stats"]),
395+
)
386396
@click.option("--schedule", is_flag=True, help="Schedule jobs to run every 10 minutes.")
387397
@click.pass_context
388-
def run(context, schedule):
398+
def run(context, analysis_type, schedule):
389399
"""
390400
Run all commands.
391401
@@ -400,10 +410,30 @@ def _run():
400410
project_ids = context.invoke(run_firebase_to_postgres)
401411
context.invoke(run_generate_stats, project_ids=project_ids)
402412

413+
def _run_creation():
414+
logger.info("start mapswipe backend workflow for creation.")
415+
context.invoke(run_create_projects)
416+
context.invoke(run_create_tutorials)
417+
418+
def _run_stats():
419+
logger.info("start mapswipe backend workflow for stats.")
420+
project_ids = context.invoke(run_firebase_to_postgres)
421+
context.invoke(run_generate_stats, project_ids=project_ids)
422+
403423
if schedule:
404-
sched.every(10).minutes.do(_run).run()
424+
if analysis_type == "all":
425+
sched.every(10).minutes.do(_run).run()
426+
elif analysis_type == "creation":
427+
sched.every(10).minutes.do(_run_creation).run()
428+
elif analysis_type == "stats":
429+
sched.every(10).minutes.do(_run_stats).run()
405430
while True:
406431
sched.run_pending()
407432
time.sleep(1)
408433
else:
409-
_run()
434+
if analysis_type == "all":
435+
sched.every(10).minutes.do(_run).run()
436+
elif analysis_type == "creation":
437+
sched.every(10).minutes.do(_run_creation).run()
438+
elif analysis_type == "stats":
439+
sched.every(10).minutes.do(_run_stats).run()

recreate_container.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
# This script builds and starts all Docker container for running the Mapswipe ecosystem.
33
# It is run either manually or by an Ansible Playbook after a successful Travis build.
44

5-
docker-compose build --no-cache postgres firebase_deploy mapswipe_workers manager_dashboard nginx api
5+
docker-compose build --no-cache postgres firebase_deploy mapswipe_workers_creation mapswipe_workers_stats manager_dashboard nginx api
66
if [[ $? = 0 ]]; then
77
echo "success"
88
else
99
echo "failure: $?"
1010
exit
1111
fi
1212

13-
docker-compose up -d --force-recreate postgres firebase_deploy mapswipe_workers manager_dashboard nginx api
13+
docker-compose up -d --force-recreate postgres firebase_deploy mapswipe_workers_creation mapswipe_workers_stats manager_dashboard nginx api
1414
if [[ $? = 0 ]]; then
1515
echo "success"
1616
else

0 commit comments

Comments
 (0)