forked from Cloud-CV/EvalAI
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backend: Replace RabbitMQ with SQS (Cloud-CV#1752)
- Loading branch information
Showing
19 changed files
with
175 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,70 @@ | ||
from __future__ import absolute_import | ||
|
||
from django.conf import settings | ||
|
||
import json | ||
import pika | ||
import logging | ||
import os | ||
|
||
import botocore | ||
import boto3 | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
def publish_submission_message(challenge_id, phase_id, submission_id): | ||
|
||
connection = pika.BlockingConnection(pika.ConnectionParameters( | ||
host=settings.RABBITMQ_PARAMETERS['HOST'])) | ||
channel = connection.channel() | ||
channel.exchange_declare(exchange='evalai_submissions', type='topic') | ||
def get_or_create_sqs_queue(): | ||
""" | ||
Returns: | ||
Returns the SQS Queue object | ||
""" | ||
sqs = boto3.resource('sqs', | ||
endpoint_url=os.environ.get('AWS_SQS_ENDPOINT', 'http://sqs:9324'), | ||
region_name=os.environ.get('AWS_DEFAULT_REGION', 'us-east-1')) | ||
|
||
# though worker is creating the queue(queue creation is idempotent too) | ||
# but lets create the queue here again, so that messages dont get missed | ||
# later on we can apply a check on queue message length to raise some alert | ||
# this way we will be notified of worker being up or not | ||
channel.queue_declare(queue='submission_task_queue', durable=True) | ||
AWS_SQS_QUEUE_NAME = os.environ.get('AWS_SQS_QUEUE_NAME', 'evalai_submission_queue') | ||
# Check if the FIFO queue exists. If no, then create one | ||
try: | ||
queue = sqs.get_queue_by_name(QueueName=AWS_SQS_QUEUE_NAME) | ||
except botocore.exceptions.ClientError as ex: | ||
if ex.response['Error']['Code'] == 'AWS.SimpleQueueService.NonExistentQueue': | ||
if settings.DEBUG: | ||
queue = sqs.create_queue(QueueName=AWS_SQS_QUEUE_NAME) | ||
else: | ||
# create a FIFO queue in the production environment | ||
name = AWS_SQS_QUEUE_NAME + '.fifo' | ||
queue = sqs.create_queue( | ||
QueueName=name, | ||
Attributes={ | ||
'FifoQueue': 'true', | ||
'ContentBasedDeduplication': 'true' | ||
} | ||
) | ||
else: | ||
logger.info("Cannot get or create Queue") | ||
return queue | ||
|
||
|
||
def publish_submission_message(challenge_id, phase_id, submission_id): | ||
""" | ||
Args: | ||
challenge_id: Challenge Id | ||
phase_id: Challenge Phase Id | ||
submission_id: Submission Id | ||
Returns: | ||
Returns SQS response | ||
""" | ||
message = { | ||
'challenge_id': challenge_id, | ||
'phase_id': phase_id, | ||
'submission_id': submission_id | ||
'submission_id': submission_id, | ||
} | ||
channel.basic_publish(exchange='evalai_submissions', | ||
routing_key='submission.*.*', | ||
body=json.dumps(message), | ||
properties=pika.BasicProperties(delivery_mode=2)) # make message persistent | ||
|
||
print(" [x] Sent %r" % message) | ||
connection.close() | ||
queue = get_or_create_sqs_queue() | ||
AWS_SQS_MESSAGE_GROUP_ID = os.environ.get('AWS_SQS_MESSAGE_GROUP_ID', 'evalai_msg_group') | ||
response = queue.send_message( | ||
MessageBody=json.dumps(message), | ||
MessageGroupId=AWS_SQS_MESSAGE_GROUP_ID, | ||
) | ||
return response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
AWS_SECRET_ACCESS_KEY=x | ||
AWS_ACCESS_KEY_ID=x | ||
|
||
DEBUG=True | ||
DJANGO_SETTINGS_MODULE=settings.dev | ||
DJANGO_SERVER=django | ||
|
||
POSTGRES_NAME=postgres | ||
POSTGRES_USER=postgres | ||
POSTGRES_PASSWORD=postgres | ||
POSTGRES_HOST=db | ||
POSTGRES_PORT=5432 | ||
|
||
DJANGO_SERVER=django | ||
|
||
RABBITMQ_HOST=rabbitmq |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,4 @@ | |
7 | ||
8 | ||
9 | ||
10 | ||
10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
asgi-redis==1.4.3 | ||
boto3==1.7.31 | ||
botocore==1.10.12 | ||
commonmark==0.5.4 | ||
django==1.11 | ||
django-import-export==0.5.1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
networkx==2.1 | ||
numpy==1.14.5 | ||
scipy==1.1.0 | ||
sklearn==0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Oops, something went wrong.