-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add script to trigger resync old conventions to PE
- Loading branch information
Showing
3 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
back/src/adapters/primary/scripts/triggerResyncOldConventionsToPE.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import axios from "axios"; | ||
import { Pool } from "pg"; | ||
import { GetAccessTokenResponse } from "../../../domain/convention/ports/PoleEmploiGateway"; | ||
import { ResyncOldConventionToPe } from "../../../domain/convention/useCases/ResyncOldConventionsToPe"; | ||
import { noRetries } from "../../../domain/core/ports/RetryStrategy"; | ||
import { createLogger } from "../../../utils/logger"; | ||
import { InMemoryCachingGateway } from "../../secondary/core/InMemoryCachingGateway"; | ||
import { RealTimeGateway } from "../../secondary/core/TimeGateway/RealTimeGateway"; | ||
import { HttpPoleEmploiGateway } from "../../secondary/poleEmploi/HttpPoleEmploiGateway"; | ||
import { createPoleEmploiTargets } from "../../secondary/poleEmploi/PoleEmploi.targets"; | ||
import { AppConfig } from "../config/appConfig"; | ||
import { configureCreateHttpClientForExternalApi } from "../config/createHttpClientForExternalApi"; | ||
import { createUowPerformer } from "../config/uowConfig"; | ||
import { handleEndOfScriptNotification } from "./handleEndOfScriptNotification"; | ||
|
||
const logger = createLogger(__filename); | ||
|
||
const config = AppConfig.createFromEnv(); | ||
|
||
const executeUsecase = async () => { | ||
const timeGateway = new RealTimeGateway(); | ||
|
||
const httpPoleEmploiGateway = new HttpPoleEmploiGateway( | ||
configureCreateHttpClientForExternalApi( | ||
axios.create({ timeout: config.externalAxiosTimeout }), | ||
)(createPoleEmploiTargets(config.peApiUrl)), | ||
new InMemoryCachingGateway<GetAccessTokenResponse>( | ||
timeGateway, | ||
"expires_in", | ||
), | ||
config.peApiUrl, | ||
config.poleEmploiAccessTokenConfig, | ||
noRetries, | ||
); | ||
|
||
const { uowPerformer } = createUowPerformer( | ||
config, | ||
() => | ||
new Pool({ | ||
connectionString: config.pgImmersionDbUrl, | ||
}), | ||
); | ||
|
||
const resyncOldConventionToPEUsecase = new ResyncOldConventionToPe( | ||
uowPerformer, | ||
httpPoleEmploiGateway, | ||
timeGateway, | ||
50, | ||
); | ||
|
||
return resyncOldConventionToPEUsecase.execute(); | ||
}; | ||
|
||
/* eslint-disable @typescript-eslint/no-floating-promises */ | ||
handleEndOfScriptNotification( | ||
"resyncOldConventionToPE", | ||
config, | ||
executeUsecase, | ||
(report) => { | ||
const errors = Object.entries(report.errors).map( | ||
([key, error]) => `${key}: ${error.message} `, | ||
); | ||
|
||
const skips = Object.entries(report.skips).map( | ||
([key, reason]) => `${key}: ${reason} `, | ||
); | ||
|
||
return [ | ||
`Total of convention to sync : ${ | ||
report.success + errors.length + errors.length | ||
}`, | ||
`Number of successfully sync convention : ${report.success}`, | ||
`Number of failures : ${errors.length}`, | ||
`Number of skips : ${skips.length}`, | ||
...(errors.length > 0 ? [`Failures : ${errors.join("\n")}`] : []), | ||
...(skips.length > 0 ? [`Skips : ${skips.join("\n")}`] : []), | ||
].join("\n"); | ||
}, | ||
logger, | ||
); |