1
1
import * as url from 'node:url' ;
2
2
3
- import yargs from 'yargs' ;
4
-
5
3
import { disconnect , knex } from '../../db/knex-database-connection.js' ;
6
4
import * as knowledgeElementSnapshotRepository from '../../src/prescription/campaign/infrastructure/repositories/knowledge-element-snapshot-repository.js' ;
7
5
import { KnowledgeElementCollection } from '../../src/prescription/shared/domain/models/KnowledgeElementCollection.js' ;
@@ -12,39 +10,7 @@ import { PromiseUtils } from '../../src/shared/infrastructure/utils/promise-util
12
10
const DEFAULT_MAX_SNAPSHOT_COUNT = 5000 ;
13
11
const DEFAULT_CONCURRENCY = 3 ;
14
12
15
- function _validateAndNormalizeMaxSnapshotCount ( maxSnapshotCount ) {
16
- if ( isNaN ( maxSnapshotCount ) ) {
17
- maxSnapshotCount = DEFAULT_MAX_SNAPSHOT_COUNT ;
18
- }
19
- if ( maxSnapshotCount <= 0 || maxSnapshotCount > 50000 ) {
20
- throw new Error ( `Nombre max de snapshots ${ maxSnapshotCount } ne peut pas être inférieur à 1 ni supérieur à 50000.` ) ;
21
- }
22
-
23
- return maxSnapshotCount ;
24
- }
25
-
26
- function _validateAndNormalizeConcurrency ( concurrency ) {
27
- if ( isNaN ( concurrency ) ) {
28
- concurrency = DEFAULT_CONCURRENCY ;
29
- }
30
- if ( concurrency <= 0 || concurrency > 10 ) {
31
- throw new Error ( `Concurrent ${ concurrency } ne peut pas être inférieur à 1 ni supérieur à 10.` ) ;
32
- }
33
-
34
- return concurrency ;
35
- }
36
-
37
- function _validateAndNormalizeArgs ( { concurrency, maxSnapshotCount } ) {
38
- const finalMaxSnapshotCount = _validateAndNormalizeMaxSnapshotCount ( maxSnapshotCount ) ;
39
- const finalConcurrency = _validateAndNormalizeConcurrency ( concurrency ) ;
40
-
41
- return {
42
- maxSnapshotCount : finalMaxSnapshotCount ,
43
- concurrency : finalConcurrency ,
44
- } ;
45
- }
46
-
47
- async function getEligibleCampaignParticipations ( maxSnapshotCount ) {
13
+ async function getEligibleCampaignParticipations ( maxSnapshotCount = DEFAULT_MAX_SNAPSHOT_COUNT ) {
48
14
return knex ( 'campaign-participations' )
49
15
. select ( 'campaign-participations.id' , 'campaign-participations.userId' , 'campaign-participations.sharedAt' )
50
16
. leftJoin (
@@ -60,7 +26,7 @@ async function getEligibleCampaignParticipations(maxSnapshotCount) {
60
26
61
27
async function generateKnowledgeElementSnapshots (
62
28
campaignParticipationData ,
63
- concurrency ,
29
+ concurrency = DEFAULT_CONCURRENCY ,
64
30
dependencies = { knowledgeElementRepository, knowledgeElementSnapshotRepository } ,
65
31
) {
66
32
return PromiseUtils . map (
@@ -90,23 +56,9 @@ const modulePath = url.fileURLToPath(import.meta.url);
90
56
const isLaunchedFromCommandLine = process . argv [ 1 ] === modulePath ;
91
57
92
58
async function main ( ) {
93
- const commandLineArgs = yargs
94
- . option ( 'maxSnapshotCount' , {
95
- description : 'Nombre de snapshots max. à générer.' ,
96
- type : 'number' ,
97
- default : DEFAULT_MAX_SNAPSHOT_COUNT ,
98
- } )
99
- . option ( 'concurrency' , {
100
- description : 'Concurrence' ,
101
- type : 'number' ,
102
- default : DEFAULT_CONCURRENCY ,
103
- } )
104
- . help ( ) . argv ;
105
- const { maxSnapshotCount, concurrency } = _validateAndNormalizeArgs ( commandLineArgs ) ;
106
-
107
- const campaignParticipationData = await getEligibleCampaignParticipations ( maxSnapshotCount ) ;
59
+ const campaignParticipationData = await getEligibleCampaignParticipations ( ) ;
108
60
109
- await generateKnowledgeElementSnapshots ( campaignParticipationData , concurrency ) ;
61
+ await generateKnowledgeElementSnapshots ( campaignParticipationData ) ;
110
62
}
111
63
112
64
( async ( ) => {
@@ -115,7 +67,6 @@ async function main() {
115
67
await main ( ) ;
116
68
} catch ( error ) {
117
69
console . error ( '\x1b[31mErreur : %s\x1b[0m' , error . message ) ;
118
- yargs . showHelp ( ) ;
119
70
process . exitCode = 1 ;
120
71
} finally {
121
72
await disconnect ( ) ;
0 commit comments