import * as _ from 'lodash'; import { AQueue } from './AQueue'; import { sendItemsToMongoApi } from './bulk-api'; export interface IMongoApiQueueOptions { batch?: number; key: string; queueName?: string; dbName?: string; colName?: string; } export class AMongoApiQueue extends AQueue { list: any = []; batch; key; queueName; dbName: string; colName: string; timer; constructor ({ batch = 1, key = 'url', queueName = '', dbName = '', colName = '', }: IMongoApiQueueOptions) { super({ batch }); this.dbName = dbName; this.colName = colName; this.batch = batch; this.key = key; this.queueName = queueName; } async send(items = this.list) { if (items.length > 0) { await sendItemsToMongoApi(this.dbName, this.colName, this.key, items); const keys = items.map((item) => item[this.key]); this.list = this.list.filter(i => keys.includes(i[this.key])); } } }