Skip to content

Commit c93f174

Browse files
committed
feat: add max pages
Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
1 parent 7094e5e commit c93f174

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

services/apps/script_executor_worker/src/bin/recalculate-all-affiliations.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
* --start-after <id> Resume from a specific memberId (exclusive, for restarts)
2727
* --dry-run Log what would be processed without starting workflows
2828
* --limit <n> Stop after triggering at most N workflows (for testing)
29+
* --max-pages <n> Stop after processing at most N pages (useful for dry-run testing)
2930
* --workflow-delay <ms> Milliseconds to wait after each workflow start (default: 0)
3031
*
3132
* Environment Variables Required:
@@ -61,6 +62,7 @@ interface ScriptOptions {
6162
startAfter: string | null
6263
dryRun: boolean
6364
limit: number | null
65+
maxPages: number | null
6466
}
6567

6668
function parseArgs(): ScriptOptions {
@@ -80,6 +82,8 @@ function parseArgs(): ScriptOptions {
8082
const dryRun = args.includes('--dry-run')
8183
const limitRaw = getArg('--limit')
8284
const limit = limitRaw !== undefined ? parseInt(limitRaw, 10) : null
85+
const maxPagesRaw = getArg('--max-pages')
86+
const maxPages = maxPagesRaw !== undefined ? parseInt(maxPagesRaw, 10) : null
8387

8488
if (isNaN(pageSize) || pageSize <= 0) {
8589
log.error('--page-size must be a positive integer')
@@ -101,8 +105,12 @@ function parseArgs(): ScriptOptions {
101105
log.error('--limit must be a positive integer')
102106
process.exit(1)
103107
}
108+
if (maxPages !== null && (isNaN(maxPages) || maxPages <= 0)) {
109+
log.error('--max-pages must be a positive integer')
110+
process.exit(1)
111+
}
104112

105-
return { pageSize, concurrency, pageDelayMs, workflowDelayMs, startAfter, dryRun, limit }
113+
return { pageSize, concurrency, pageDelayMs, workflowDelayMs, startAfter, dryRun, limit, maxPages }
106114
}
107115

108116
// Returns a page of distinct memberIds from memberOrganizations, cursor-based.
@@ -230,6 +238,7 @@ async function main() {
230238
log.info(`Start after: ${opts.startAfter ?? '(beginning)'}`)
231239
log.info(`Mode: ${opts.dryRun ? 'DRY RUN' : 'LIVE'}`)
232240
log.info(`Limit: ${opts.limit ?? '(none)'}`)
241+
log.info(`Max pages: ${opts.maxPages ?? '(none)'}`)
233242
log.info('='.repeat(80))
234243

235244
const dbConnection = await getDbConnection(WRITE_DB_CONFIG())
@@ -336,6 +345,11 @@ async function main() {
336345
hasMore = false
337346
}
338347

348+
if (opts.maxPages !== null && pageNum >= opts.maxPages) {
349+
log.info(`Max pages of ${opts.maxPages} reached.`)
350+
hasMore = false
351+
}
352+
339353
if (opts.pageDelayMs > 0) {
340354
await new Promise((resolve) => setTimeout(resolve, opts.pageDelayMs))
341355
}

0 commit comments

Comments
 (0)