Skip to content

Commit 85d535e

Browse files
committed
refactor: better text on util function
1 parent 750c80d commit 85d535e

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

services/triggerService.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { fetchPaybuttonById, fetchPaybuttonWithTriggers } from './paybuttonServi
88
import config from 'config'
99
import { MAIL_FROM, MAIL_HTML_REPLACER, MAIL_SUBJECT, getMailerTransporter } from 'constants/mail'
1010
import { getTransactionValue } from './transactionService'
11-
import { runAsyncInBatches } from 'utils'
11+
import { runAsyncInBatches } from 'utils/index'
1212

1313
// Include Paybutton.owner user inline so we don't refetch per trigger
1414
const triggerWithPaybuttonAndUserInclude = {
@@ -559,11 +559,13 @@ export async function executeTriggersBatch (broadcasts: BroadcastTxData[], netwo
559559

560560
console.log(`[TRIGGER ${currency}]: executing posts with concurrency=${TRIGGER_POST_CONCURRENCY}`)
561561
await runAsyncInBatches(
562+
`${currency} POST TRIGGERS`,
562563
postUserRunners.map(run => async () => { postResults.push(await run()) }),
563564
TRIGGER_POST_CONCURRENCY
564565
)
565566
console.log(`[TRIGGER ${currency}]: executing emails with concurrency=${TRIGGER_EMAIL_CONCURRENCY}`)
566567
await runAsyncInBatches(
568+
`${currency} POST TRIGGERS`,
567569
emailUserRunners.map(run => async () => { emailResults.push(await run()) }),
568570
TRIGGER_EMAIL_CONCURRENCY
569571
)

utils/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,11 @@ export const removeUnserializableFields = (user: UserProfile): void => {
237237
(user.updatedAt as any) = user.updatedAt.toString()
238238
}
239239

240-
export async function runAsyncInBatches (tasks: Array<() => Promise<void>>, batchSize: number): Promise<void> {
241-
console.log('(PARALLEL) Will run ', tasks.length, 'tasks.')
240+
export async function runAsyncInBatches (taskName: string, tasks: Array<() => Promise<void>>, batchSize: number): Promise<void> {
241+
console.log(`[${batchSize}-PARALLEL: ${taskName}] Will run ${tasks.length} tasks.`)
242242
for (let i = 0; i < tasks.length; i += batchSize) {
243243
const slice = tasks.slice(i, i + batchSize)
244-
console.log('(PARALLEL) Running batch of', slice.length, 'tasks....')
244+
console.log(`[${batchSize}-PARALLEL: ${taskName}] Running batch of ${slice.length} tasks....`)
245245
await Promise.all(slice.map(async fn => await fn()))
246246
}
247247
}

0 commit comments

Comments
 (0)