Skip to content

Commit

Permalink
run clean documents before export scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine Jeanneney committed Jan 31, 2024
1 parent 62b3606 commit 745261a
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 23 deletions.
2 changes: 1 addition & 1 deletion ansible/roles/deploy_backend/defaults/main/defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
active_deadline_seconds: 1800
command: "dist/scripts/importChainedDocumentsFromSder.js --count 500 --threshold 1500"
- name: "export-j-4"
schedule: "30 17 * * *"
schedule: "25 17 * * *"
successful_jobs_history_limit: 7
failed_jobs_history_limit: 7
backoff_limit: 2
Expand Down
12 changes: 0 additions & 12 deletions packages/courDeCassation/src/scripts/cleanOrphansTreatments.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import { parametersHandler } from '../lib/parametersHandler';
(async () => {
const { environment, settings } = await parametersHandler.getParameters();
const backend = buildBackend(environment, settings);

await backend.runScript(
() => backend.scripts.cleanDocuments.run(),
backend.scripts.cleanDocuments.option,
);

const sderExporter = buildSderExporter(environment, settings);
backend.runScript(
() => sderExporter.exportAllRejectedDocuments(environment),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import { parametersHandler } from '../lib/parametersHandler';
(async () => {
const { environment, settings } = await parametersHandler.getParameters();
const backend = buildBackend(environment, settings);

await backend.runScript(
() => backend.scripts.cleanDocuments.run(),
backend.scripts.cleanDocuments.option,
);

const sderExporter = buildSderExporter(environment, settings);

backend.runScript(() => sderExporter.exportAllTreatedDocuments(environment), {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import { parametersHandler } from '../lib/parametersHandler';
const { environment, settings } = await parametersHandler.getParameters();
const { days } = parseArgv();
const backend = buildBackend(environment, settings);

await backend.runScript(
() => backend.scripts.cleanDocuments.run(),
backend.scripts.cleanDocuments.option,
);

const sderExporter = buildSderExporter(environment, settings);
backend.runScript(
() => sderExporter.exportTreatedDocumentsSince(days, environment),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import { parametersHandler } from '../lib/parametersHandler';
(async () => {
const { environment, settings } = await parametersHandler.getParameters();
const backend = buildBackend(environment, settings);

await backend.runScript(
() => backend.scripts.cleanDocuments.run(),
backend.scripts.cleanDocuments.option,
);

const sderExporter = buildSderExporter(environment, settings);

backend.runScript(
Expand Down
5 changes: 0 additions & 5 deletions packages/generic/backend/src/app/buildBackend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
resetUntreatedDocumentsForTest,
revertOneMigration,
runNewMigrations,
cleanOrphansTreatments,
} from './scripts';

export { buildBackend };
Expand Down Expand Up @@ -111,10 +110,6 @@ function buildBackend(environment: environmentType, settings: settingsType) {
run: runNewMigrations,
option: { shouldLoadDb: true, shouldExit: true },
},
cleanOrphansTreatments: {
run: cleanOrphansTreatments,
option: { shouldLoadDb: true, shouldExit: true },
},
},
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { logger } from '../../../utils';
export { cleanDuplicatedDocuments };

/**
* Delete all doubled documents (same source, same documentNumber, same text and creationDate ) get recent documents by creationDate
* Delete all doubled documents (same source, same documentNumber and same text) keep the most recent document by dateCreation
*/
async function cleanDuplicatedDocuments() {
logger.log({ operationName: 'cleanDuplicatedDocuments', msg: 'START' });
Expand All @@ -28,11 +28,10 @@ async function cleanDuplicatedDocuments() {
for (let index = 0, l = documents.length - 1; index < l; index++) {
const currentDocument = sortedDocuments[index];
const nextDocument = sortedDocuments[index + 1];
// check if document is same, if same return the last version document
if (areDocumentsIdentical(currentDocument, nextDocument)) {
if (
currentDocument.creationDate &&
nextDocument.creationDate != undefined &&
nextDocument.creationDate &&
currentDocument.creationDate > nextDocument.creationDate
) {
documentsToDelete.push(nextDocument);
Expand Down
2 changes: 0 additions & 2 deletions packages/generic/backend/src/app/scripts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { resetUntreatedDocumentsForTest } from './resetUntreatedDocumentsForTest
import { purgeDb } from './purgeDb';
import { renewCache } from './renewCache';
import { setIndexesOnAllCollections } from './setIndexesOnAllCollections';
import { cleanOrphansTreatments } from './cleanDocuments/cleanOrphansTreatments';

export {
cleanDocuments,
Expand All @@ -43,5 +42,4 @@ export {
revertOneMigration,
runNewMigrations,
setIndexesOnAllCollections,
cleanOrphansTreatments,
};

0 comments on commit 745261a

Please sign in to comment.