Skip to content

Commit

Permalink
api: disable rq, exec
Browse files Browse the repository at this point in the history
  • Loading branch information
tschaume committed Jan 27, 2022
1 parent 6dcb9da commit 7981454
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
50 changes: 25 additions & 25 deletions mpcontribs-api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,28 @@ def start(program):

start("apis:*")

metadata_uri = os.environ.get("METADATA_URI", "")
start_rq = True

if metadata_uri:
# in AWS Fargate with potentially multiple tasks
print("METADATA URI", metadata_uri)
r = requests.get(metadata_uri)
labels = r.json()["Labels"]
prefix = "com.amazonaws.ecs"
cluster = labels[f"{prefix}.cluster"].split("/", 1)[1]
family = labels[f"{prefix}.task-definition-family"]
version = int(labels[f"{prefix}.task-definition-version"])
task_arns = client.list_tasks(cluster=cluster, family=family).get("taskArns", [])
tasks = client.describe_tasks(cluster=cluster, tasks=task_arns).get("tasks", [])
ntasks = 0

for task in tasks:
v = int(task["taskDefinitionArn"].rsplit(":", 1)[1])
ntasks += int(v == version)

start_rq = ntasks == 1 # this task included in metadata response
print(f"TASKS {ntasks}/{len(tasks)} -> START RQ {start_rq}")

if start_rq:
start("rq:*")
#metadata_uri = os.environ.get("METADATA_URI", "")
#start_rq = True
#
#if metadata_uri:
# # in AWS Fargate with potentially multiple tasks
# print("METADATA URI", metadata_uri)
# r = requests.get(metadata_uri)
# labels = r.json()["Labels"]
# prefix = "com.amazonaws.ecs"
# cluster = labels[f"{prefix}.cluster"].split("/", 1)[1]
# family = labels[f"{prefix}.task-definition-family"]
# version = int(labels[f"{prefix}.task-definition-version"])
# task_arns = client.list_tasks(cluster=cluster, family=family).get("taskArns", [])
# tasks = client.describe_tasks(cluster=cluster, tasks=task_arns).get("tasks", [])
# ntasks = 0
#
# for task in tasks:
# v = int(task["taskDefinitionArn"].rsplit(":", 1)[1])
# ntasks += int(v == version)
#
# start_rq = ntasks == 1 # this task included in metadata response
# print(f"TASKS {ntasks}/{len(tasks)} -> START RQ {start_rq}")
#
#if start_rq:
# start("rq:*")
2 changes: 1 addition & 1 deletion mpcontribs-api/scripts/start_rq.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

wait-for-it.sh $JUPYTER_GATEWAY_HOST -s -t 50 -- wait-for-it.sh $MPCONTRIBS_API_HOST -s -t 15 -- ddtrace-run flask rq $1
exec wait-for-it.sh $JUPYTER_GATEWAY_HOST -s -t 50 -- wait-for-it.sh $MPCONTRIBS_API_HOST -s -t 15 -- ddtrace-run flask rq $1

0 comments on commit 7981454

Please sign in to comment.