import * as _ from 'lodash'; import { AQueue } from './AQueue'; import { toSnake, sendItemsToAwsPg } from './utils'; export interface IPgApiQueueOptions { batch?: number; key: string; queueName?: string; tableName?: string; } export class APgApiQueue extends AQueue { list: any = []; batch; key; queueName; dbName: string; tableName: string; timer; constructor ({ batch = 1, key = 'url', queueName = '', tableName: colName = '', }: IPgApiQueueOptions) { super({ batch }); this.tableName = colName; this.batch = batch; this.key = key; this.queueName = queueName; } async send(items = this.list) { console.info('\n%c--------- send --------- \n', 'background:yellow; color:blue; font-weight:600;'); if (items.length > 0) { const fmtItems = toSnake(items); return sendItemsToAwsPg(this.tableName, this.key, fmtItems); } return null } }