Open
Description
We have endpoint /v5/projects/admin/es/project/index
which we call to index multiple projects from DB to ES by defining a range of projects ids from projectIdStart
to projectIdEnd
.
At the moment this endpoint only responds after we prepare data for indexing and it doesn't wait until the actual indexing is finished. So we have to see the console of the server to see the logs if we want to understand when the indexing is ready and if there were any errors during indexing or no.
- We want to see the progress with log when we run this endpoint in response. But we don't want to wait until everything is done, so the response hangs for a long time and only after all is done we can see the log. Response should be returned in parts using streams see https://stackoverflow.com/questions/38788721/how-do-i-stream-response-in-express, so we would see the constant update of response when we are calling this endpoint.
The can be implemented the next way:
- create a new
logger
which would do 2 things:- log to the console as it's done now by
req.log
logger - write to response stream
- for example such a custom logger can be created like this https://github.com/topcoder-platform/tc-project-service/blob/develop/src/routes/admin/es-fix-metadata-for-es.js#L11-L38, but instead of writing to an array it should write to the response stream
- log to the console as it's done now by
- this new logger might have a special method to mark the stream
end
so we can close the connection when everything is done. - while we log to console in JSON format, in the response we should return in the next format:
<log_type>: <message>
, examples:INFO: Getting user details.
ERROR: Cannot get user details.
DEBUG: User details: {"id:"11232,"name":"Test"}.
WARNING: ...