Skip to content

Commit

Permalink
logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ericjeangirard committed Oct 22, 2024
1 parent c93b2a5 commit fd87011
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
5 changes: 3 additions & 2 deletions server/src/routes/works.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ const getWorks = async ({ options, resetCache = false }) => {
const shasum = crypto.createHash('sha1');
shasum.update(JSON.stringify(options));
const searchId = shasum.digest('hex');
const queryId = Math.floor(Math.random() * SEED_MAX);
const start = new Date();
const queryId = start.toISOString().concat(' - ', Math.floor(Math.random() * SEED_MAX).toString());
let cache = false;
if (USE_CACHE) {
console.time(
Expand Down Expand Up @@ -197,7 +198,7 @@ const getWorks = async ({ options, resetCache = false }) => {
console.time(
`7. Query ${queryId} | Save cache ${options.affiliationStrings}`,
);
await saveCache({ result, searchId });
await saveCache({ result, searchId, queryId });
console.timeEnd(
`7. Query ${queryId} | Save cache ${options.affiliationStrings}`,
);
Expand Down
12 changes: 10 additions & 2 deletions server/src/utils/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ const getCache = async ({ searchId }) => {
return false;
};

const saveCache = async ({ result, searchId }) => {
const saveCache = async ({ result, searchId, queryId }) => {
console.log(queryId, 'start saving cache');
const fileName = getFileName(searchId);
const remotePath = `${OS_CONTAINER}/${fileName}`;

Expand Down Expand Up @@ -64,14 +65,21 @@ const saveCache = async ({ result, searchId }) => {
});
const token = response?.headers?.get('x-subject-token');
if (token) {
const resultJson = JSON.stringify(result);
console.time(
`7b. Query ${queryId} | Uploading data to cloud`,
);
await fetch(
`https://storage.gra.cloud.ovh.net/v1/AUTH_${OS_TENANT_ID}/${remotePath}`,
{
body: JSON.stringify(result),
body: resultJson,
headers: { 'Content-Type': 'application/json', 'X-Auth-Token': token, 'X-Delete-After': '604800' }, // 7 days
method: 'PUT',
},
);
console.timeEnd(
`7b. Query ${queryId} | Uploading data to cloud`,
);
}
};

Expand Down

0 comments on commit fd87011

Please sign in to comment.