{"version":3,"sources":["../../../../src/queues/operations/handleSchedules/countRunnableOrActiveJobsForQueue.ts"],"sourcesContent":["import type { PayloadRequest, Where } from '../../../types/index.js'\nimport type { TaskType } from '../../config/types/taskTypes.js'\nimport type { WorkflowTypes } from '../../config/types/workflowTypes.js'\n\n/**\n * Gets all queued jobs that can be run. This means they either:\n * - failed but do not have a definitive error => can be retried\n * - are currently processing\n * - have not been started yet\n */\nexport async function countRunnableOrActiveJobsForQueue({\n onlyScheduled = false,\n queue,\n req,\n taskSlug,\n workflowSlug,\n}: {\n /**\n * If true, this counts only jobs that have been created through the scheduling system.\n *\n * @default false\n */\n onlyScheduled?: boolean\n queue: string\n req: PayloadRequest\n taskSlug?: TaskType\n workflowSlug?: WorkflowTypes\n}): Promise {\n const and: Where[] = [\n {\n queue: {\n equals: queue,\n },\n },\n\n {\n completedAt: { exists: false },\n },\n {\n error: { exists: false },\n },\n ]\n\n if (taskSlug) {\n and.push({\n taskSlug: {\n equals: taskSlug,\n },\n })\n } else if (workflowSlug) {\n and.push({\n workflowSlug: {\n equals: workflowSlug,\n },\n })\n }\n if (onlyScheduled) {\n and.push({\n 'meta.scheduled': {\n equals: true,\n },\n })\n }\n\n const runnableOrActiveJobsForQueue = await req.payload.db.count({\n collection: 'payload-jobs',\n req,\n where: {\n and,\n },\n })\n\n return runnableOrActiveJobsForQueue.totalDocs\n}\n"],"names":["countRunnableOrActiveJobsForQueue","onlyScheduled","queue","req","taskSlug","workflowSlug","and","equals","completedAt","exists","error","push","runnableOrActiveJobsForQueue","payload","db","count","collection","where","totalDocs"],"mappings":"AAIA;;;;;CAKC,GACD,OAAO,eAAeA,kCAAkC,EACtDC,gBAAgB,KAAK,EACrBC,KAAK,EACLC,GAAG,EACHC,QAAQ,EACRC,YAAY,EAYb;IACC,MAAMC,MAAe;QACnB;YACEJ,OAAO;gBACLK,QAAQL;YACV;QACF;QAEA;YACEM,aAAa;gBAAEC,QAAQ;YAAM;QAC/B;QACA;YACEC,OAAO;gBAAED,QAAQ;YAAM;QACzB;KACD;IAED,IAAIL,UAAU;QACZE,IAAIK,IAAI,CAAC;YACPP,UAAU;gBACRG,QAAQH;YACV;QACF;IACF,OAAO,IAAIC,cAAc;QACvBC,IAAIK,IAAI,CAAC;YACPN,cAAc;gBACZE,QAAQF;YACV;QACF;IACF;IACA,IAAIJ,eAAe;QACjBK,IAAIK,IAAI,CAAC;YACP,kBAAkB;gBAChBJ,QAAQ;YACV;QACF;IACF;IAEA,MAAMK,+BAA+B,MAAMT,IAAIU,OAAO,CAACC,EAAE,CAACC,KAAK,CAAC;QAC9DC,YAAY;QACZb;QACAc,OAAO;YACLX;QACF;IACF;IAEA,OAAOM,6BAA6BM,SAAS;AAC/C"}