fixed error and made batch timings a little more dynamic depending on batch total instead of 15 min spread
This commit is contained in:
parent
b2817656b3
commit
8a588816c4
3 changed files with 47 additions and 51 deletions
|
|
@ -208,11 +208,11 @@ export class BatchProcessor {
|
|||
* Process a batch (called by batch jobs)
|
||||
*/
|
||||
async processBatch<T>(payload: {
|
||||
items: T[];
|
||||
batchIndex: number;
|
||||
total: number;
|
||||
config: BatchConfig<T>;
|
||||
}) {
|
||||
items: T[];
|
||||
batchIndex: number;
|
||||
total: number;
|
||||
config: BatchConfig<T>;
|
||||
}, createJobData?: (item: T, index: number) => any) {
|
||||
const { items, batchIndex, total, config } = payload;
|
||||
|
||||
logger.info('Processing batch', {
|
||||
|
|
@ -222,10 +222,18 @@ export class BatchProcessor {
|
|||
progress: `${((batchIndex + 1) / total * 100).toFixed(2)}%`
|
||||
});
|
||||
|
||||
const delayPerItem = Math.floor((15 * 60 * 1000) / items.length); // 15 min per batch
|
||||
const totalBatchDelayMs = config.totalDelayMs / total;
|
||||
const delayPerItem = Math.floor(totalBatchDelayMs / items.length);
|
||||
|
||||
const jobs = items.map((item, itemIndex) => {
|
||||
const userData = config.createJobData(item, itemIndex);
|
||||
// Use the provided createJobData function or fall back to config
|
||||
const jobDataFn = createJobData || config.createJobData;
|
||||
|
||||
if (!jobDataFn) {
|
||||
throw new Error('createJobData function is required');
|
||||
}
|
||||
|
||||
const userData = jobDataFn(item, itemIndex);
|
||||
|
||||
return {
|
||||
name: `${config.jobNamePrefix}-processing`,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue