Commit 1913f2cd authored by David Mendez's avatar David Mendez

Add endpoint to check status of subindex generation task

parent a96a6934
......@@ -8,6 +8,7 @@ from flask_cors import CORS
from app.config import RUN_CONFIG
# from app.cache import CACHE
from app.blueprints.swagger_description.swagger_description_blueprint import SWAGGER_BLUEPRINT
from app.blueprints.subset_generator_blueprint.controllers.subset_generator_controller import SUBSET_GENERATOR_BLUEPRINT
def create_app():
......@@ -37,6 +38,7 @@ def create_app():
# CACHE.cache._client.behaviors['retry_timeout'] = 600
flask_app.register_blueprint(SWAGGER_BLUEPRINT, url_prefix=f'{base_path}/swagger')
flask_app.register_blueprint(SUBSET_GENERATOR_BLUEPRINT, url_prefix=f'{base_path}/es_subsets')
return flask_app
......
......@@ -9,5 +9,12 @@ class SubmitSubsetGenerationRequest(Schema):
Class with the schema for submitting the generation of a subset
"""
origin_index = fields.String(required=True)
items_ids = fields.Nested(required=True)
items_ids = fields.String(required=True, many=True)
class SubsetGenerationStatusRequest(Schema):
"""
Class with the schema for requesting the status of a subset generation task
"""
task_id = fields.String(required=True)
......@@ -8,7 +8,6 @@ from app.blueprints.subset_generator_blueprint.services import subset_generator_
from app.request_validation.decorators import validate_form_with, validate_url_params_with
from app import app_logging
SUBSET_GENERATOR_BLUEPRINT = Blueprint('es_subsets', __name__)
......@@ -28,8 +27,30 @@ def submit_subset_creation_from_ids():
try:
return jsonify({'msg': 'hola'})
submission_response = subset_generator_service.submit_subset_generation_from_ids(origin_index, items_ids)
return jsonify(submission_response)
except subset_generator_service.SubsetGeneratorServiceError as error:
abort(500, msg=f'Internal server error: {str(error)}')
@SUBSET_GENERATOR_BLUEPRINT.route('/get_task_status/<task_id>', methods=['GET'])
@validate_url_params_with(marshmallow_schemas.SubsetGenerationStatusRequest)
def get_task_status(task_id):
"""
:param task_id: id of the task to check
:return: json response with status of the task
"""
try:
status_response = subset_generator_service.get_task_status(task_id)
return jsonify(status_response)
except subset_generator_service.SubsetGeneratorServiceError as error:
abort(500, msg=f'Internal server error: {str(error)}')
except subset_generator_service.SubsetGenerationTaskNotFoundError as error:
abort(404, repr(error))
\ No newline at end of file
......@@ -4,7 +4,11 @@ Subset generator service
class SubsetGeneratorServiceError(Exception):
"""Base class for exceptions in the properties configuration service."""
"""Base class for exceptions in the subset generation service."""
class SubsetGenerationTaskNotFoundError(Exception):
"""Base class for exceptions in the subset generation service."""
def submit_subset_generation_from_ids(origin_index, items_ids):
......@@ -12,9 +16,23 @@ def submit_subset_generation_from_ids(origin_index, items_ids):
Starts the process of the generation of the subset based on the ids passed as parameter
:param origin_index: source index for the subset
:param items_ids: ids of the items to include
:return: an id of the task to check it's progress
:return: a dict with the id of the task to check it's progress
"""
return {
'task_id': 'some_id'
}
def get_task_status(task_id):
"""
:param task_id: the task id to check
:return: a dict describing the status of the task
"""
return {
'task_status': 'RUNNING',
'progress': 50,
'num_items_in_subset': '20000',
'subset_index_name': 'subset_index'
}
......@@ -48,9 +48,40 @@ paths:
description: "successful operation"
schema:
$ref: '#/definitions/SubsetOperationResponse'
/es_subsets/get_task_status/{task_id}:
get:
tags:
- 'ES subsets'
summary: 'Returns the status of the subset creation task'
description: 'After submitting a task to create a subset, it returns the status of the subset creation task'
operationId: 'get_subset_index_creation_status'
produces:
- 'application/json'
parameters:
- name: 'task_id'
in: 'path'
description: 'Id of the task to check'
required: true
type: 'string'
responses:
'200':
description: "successful operation"
schema:
$ref: '#/definitions/SubsetCreationStatusResponse'
definitions:
SubsetOperationResponse:
type: 'object'
properties:
task_id:
type: 'string'
SubsetCreationStatusResponse:
type: 'object'
properties:
task_status:
type: 'string'
progress:
type: 'integer'
num_items_in_subset:
type: 'integer'
subset_index_name:
type: 'string'
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment