Skip to content

Commit

Permalink
TO REVERT - log script in prod
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine Jeanneney committed Jun 28, 2024
1 parent fc8db0d commit 7dbfa58
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 1 deletion.
10 changes: 9 additions & 1 deletion ansible/roles/deploy_backend/defaults/main/defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
- name: "renew-cache"
schedule: "*/5 6-17 * * *"
successful_jobs_history_limit: 3
failed_jobs_history_limit: 7
failed_jobs_history_limit: 7
backoff_limit: 0
parallelism: 1
active_deadline_seconds: 300
Expand All @@ -80,3 +80,11 @@ jobs:
parallelism: 1
active_deadline_seconds: 300
command: "dist/scripts/cleanDocuments.js"
- name: "daily-stats"
schedule: "0 5 31 2 *"
successful_jobs_history_limit: 7
failed_jobs_history_limit: 7
backoff_limit: 0
parallelism: 1
active_deadline_seconds: 300
command: "dist/scripts/promptDailyStats.js"
12 changes: 12 additions & 0 deletions packages/courDeCassation/src/scripts/promptDailyStats.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { buildBackend } from '@label/backend';
import { parametersHandler } from '../lib/parametersHandler';

(async () => {
const { settings } = await parametersHandler.getParameters();
const backend = buildBackend(settings);

await backend.runScript(
() => backend.scripts.promptDailyStats.run(settings),
backend.scripts.promptDailyStats.option,
);
})();
5 changes: 5 additions & 0 deletions packages/generic/backend/src/app/buildBackend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
resetUntreatedDocumentsForTest,
revertOneMigration,
runNewMigrations,
promptDailyStats,
} from './scripts';
import { cleanDuplicatedDocuments } from './scripts/cleanDocuments';

Expand Down Expand Up @@ -115,6 +116,10 @@ function buildBackend(settings: settingsType) {
run: cleanDuplicatedDocuments,
option: { shouldLoadDb: true, shouldExit: false },
},
promptDailyStats: {
run: promptDailyStats,
option: { shouldLoadDb: true, shouldExit: false },
},
},
};
}
2 changes: 2 additions & 0 deletions packages/generic/backend/src/app/scripts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { resetUntreatedDocumentsForTest } from './resetUntreatedDocumentsForTest
import { purgeDb } from './purgeDb';
import { renewCache } from './renewCache';
import { setIndexesOnAllCollections } from './setIndexesOnAllCollections';
import { promptDailyStats } from './promptDailyStats';

export {
cleanDocuments,
Expand All @@ -42,4 +43,5 @@ export {
revertOneMigration,
runNewMigrations,
setIndexesOnAllCollections,
promptDailyStats,
};
49 changes: 49 additions & 0 deletions packages/generic/backend/src/app/scripts/promptDailyStats.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { logger } from '../../utils';
import { ressourceFilterType, settingsType } from '@label/core';
import { userService } from '../../modules/user';
import { fetchAggregatedStatisticsAccordingToFilter } from '../../modules/statistic/service/fetchAggregatedStatisticsAccordingToFilter';

export { promptDailyStats };

async function promptDailyStats(settings: settingsType) {
logger.log({ operationName: 'TESTpromptDailyStats', msg: 'START' });

const activeUsers = await userService.fetchWorkingUsers();

const endDate = Date.now();
const startDate = endDate - 24 * 60 * 60 * 1000;

for (const user of activeUsers) {
const filter: ressourceFilterType = {
mustHaveSurAnnotations: false,
mustHaveSubAnnotations: false,
startDate,
endDate,
userId: user._id,
importer: undefined,
jurisdiction: undefined,
publicationCategory: undefined,
route: undefined,
source: undefined,
};

try {
const aggregatedStats = await fetchAggregatedStatisticsAccordingToFilter(
filter,
settings,
);
logger.log({
operationName: 'TESTuserDailyStats',
msg: `dailyStats of ${user.name}`,
data: { userName: user.name, ...aggregatedStats },
});
} catch (error) {
logger.error({
operationName: 'TESTpromptDailyStats',
msg: `Error fetching stats: ${error}`,
});
}
}

logger.log({ operationName: 'TESTpromptDailyStats', msg: 'END' });
}

0 comments on commit 7dbfa58

Please sign in to comment.