Repository: Cloud-CV/EvalAI

Issue:
Update submission worker to create challenge specific queues.
### Deliverables:

The submission worker should be updated so that challenge specific queues can be created instead of one single queue for all the challenges.

**Challenge Queue name:** submission_challenge_<challenge_pk>

Make sure to use the exchange type as **direct**.(refer [here](https://www.rabbitmq.com/tutorials/tutorial-four-python.html)) 


Discussion:

Resolving patch:
diff --git a/apps/challenges/views.py b/apps/challenges/views.py
--- a/apps/challenges/views.py
+++ b/apps/challenges/views.py
@@ -1332,11 +1332,18 @@ def get_broker_urls(request):
     Returns:
         Queue name of approved challenges
     """
+    is_active = request.data.get('is_active', False)
+
+    q_params = {'approved_by_admin': True}
+    if is_active:
+        q_params['start_date__lt'] = timezone.now()
+        q_params['end_date__gt'] = timezone.now()
+
     if not request.user.is_superuser:
         response_data = {'error': 'You are not authorized to make this request!'}
         return Response(response_data, status=status.HTTP_403_FORBIDDEN)
     else:
-        challenges = Challenge.objects.filter(approved_by_admin=True)
+        challenges = Challenge.objects.filter(**q_params)
         response_data = challenges.values_list('queue', flat=True)
         return Response(response_data, status=status.HTTP_200_OK)
 
diff --git a/apps/jobs/sender.py b/apps/jobs/sender.py
--- a/apps/jobs/sender.py
+++ b/apps/jobs/sender.py
@@ -15,6 +15,8 @@
 
 def get_or_create_sqs_queue(queue_name):
     """
+    Args:
+        queue_name: Name of the SQS Queue
     Returns:
         Returns the SQS Queue object
     """
@@ -24,6 +26,8 @@ def get_or_create_sqs_queue(queue_name):
                              region_name=os.environ.get('AWS_DEFAULT_REGION', 'us-east-1'),
                              aws_secret_access_key=os.environ.get('AWS_SECRET_ACCESS_KEY', 'x'),
                              aws_access_key_id=os.environ.get('AWS_ACCESS_KEY_ID', 'x'),)
+        # Use default queue name in dev and test environment
+        queue_name = 'evalai_submission_queue'
     else:
         sqs = boto3.resource('sqs',
                              region_name=os.environ.get('AWS_DEFAULT_REGION', 'us-east-1'),
@@ -33,7 +37,7 @@ def get_or_create_sqs_queue(queue_name):
     if queue_name == '':
         queue_name = 'evalai_submission_queue'
 
-    # Check if the queue exists. If no, then create one
+    # Check if the queue exists. If not, then create one.
     try:
         queue = sqs.get_queue_by_name(QueueName=queue_name)
     except botocore.exceptions.ClientError as ex:
diff --git a/scripts/workers/submission_worker.py b/scripts/workers/submission_worker.py
--- a/scripts/workers/submission_worker.py
+++ b/scripts/workers/submission_worker.py
@@ -1,4 +1,3 @@
-
 from __future__ import absolute_import
 from __future__ import division
 from __future__ import print_function
@@ -221,22 +220,14 @@ def extract_challenge_data(challenge, phases):
         raise
 
 
-def load_active_challenges():
+def load_challenge(challenge):
     '''
-         * Fetches active challenges and corresponding active phases for it.
+        Creates python package for a challenge and extracts relevant data
     '''
-    q_params = {'approved_by_admin': True}
-    q_params['start_date__lt'] = timezone.now()
-    q_params['end_date__gt'] = timezone.now()
-
     # make sure that the challenge base directory exists
     create_dir_as_python_package(CHALLENGE_DATA_BASE_DIR)
-
-    active_challenges = Challenge.objects.filter(**q_params)
-
-    for challenge in active_challenges:
-        phases = challenge.challengephase_set.all()
-        extract_challenge_data(challenge, phases)
+    phases = challenge.challengephase_set.all()
+    extract_challenge_data(challenge, phases)
 
 
 def extract_submission_data(submission_id):
@@ -540,7 +531,17 @@ def main():
     create_dir_as_python_package(COMPUTE_DIRECTORY_PATH)
     sys.path.append(COMPUTE_DIRECTORY_PATH)
 
-    load_active_challenges()
+    q_params = {'approved_by_admin': True}
+    q_params['start_date__lt'] = timezone.now()
+    q_params['end_date__gt'] = timezone.now()
+
+    challenge_pk = os.environ.get('CHALLENGE_PK')
+    if challenge_pk:
+        q_params['pk'] = challenge_pk
+
+    challenges = Challenge.objects.filter(**q_params)
+    for challenge in challenges:
+        load_challenge(challenge)
 
     # create submission base data directory
     create_dir_as_python_package(SUBMISSION_DATA_BASE_DIR)


Test patch: