queue-getters.d.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. import { QueueBase } from './queue-base';
  2. import { Job } from './job';
  3. import { JobState, JobType } from '../types';
  4. import { JobJsonRaw, Metrics, QueueMeta } from '../interfaces';
  5. /**
  6. * Provides different getters for different aspects of a queue.
  7. */
  8. export declare class QueueGetters<JobBase extends Job = Job> extends QueueBase {
  9. getJob(jobId: string): Promise<JobBase | undefined>;
  10. private commandByType;
  11. private sanitizeJobTypes;
  12. /**
  13. Returns the number of jobs waiting to be processed. This includes jobs that are
  14. "waiting" or "delayed" or "prioritized" or "waiting-children".
  15. */
  16. count(): Promise<number>;
  17. /**
  18. * Returns the time to live for a rate limited key in milliseconds.
  19. * @param maxJobs - max jobs to be considered in rate limit state. If not passed
  20. * it will return the remaining ttl without considering if max jobs is excedeed.
  21. * @returns -2 if the key does not exist.
  22. * -1 if the key exists but has no associated expire.
  23. * @see {@link https://redis.io/commands/pttl/}
  24. */
  25. getRateLimitTtl(maxJobs?: number): Promise<number>;
  26. /**
  27. * Get jobId that starts debounced state.
  28. * @deprecated use getDeduplicationJobId method
  29. *
  30. * @param id - debounce identifier
  31. */
  32. getDebounceJobId(id: string): Promise<string | null>;
  33. /**
  34. * Get jobId from deduplicated state.
  35. *
  36. * @param id - deduplication identifier
  37. */
  38. getDeduplicationJobId(id: string): Promise<string | null>;
  39. /**
  40. * Get global concurrency value.
  41. * Returns null in case no value is set.
  42. */
  43. getGlobalConcurrency(): Promise<number | null>;
  44. /**
  45. * Get global rate limit values.
  46. * Returns null in case no value is set.
  47. */
  48. getGlobalRateLimit(): Promise<{
  49. max: number;
  50. duration: number;
  51. } | null>;
  52. /**
  53. * Job counts by type
  54. *
  55. * Queue#getJobCountByTypes('completed') =\> completed count
  56. * Queue#getJobCountByTypes('completed', 'failed') =\> completed + failed count
  57. * Queue#getJobCountByTypes('completed', 'waiting', 'failed') =\> completed + waiting + failed count
  58. */
  59. getJobCountByTypes(...types: JobType[]): Promise<number>;
  60. /**
  61. * Returns the job counts for each type specified or every list/set in the queue by default.
  62. * @param types - the types of jobs to count. If not specified, it will return the counts for all types.
  63. * @returns An object, key (type) and value (count)
  64. */
  65. getJobCounts(...types: JobType[]): Promise<{
  66. [index: string]: number;
  67. }>;
  68. /**
  69. * Records job counts as gauge metrics for telemetry purposes.
  70. * Each job state count is recorded with the queue name and state as attributes.
  71. * @param types - the types of jobs to count. If not specified, it will return the counts for all types.
  72. * @returns An object, key (type) and value (count)
  73. */
  74. recordJobCountsMetric(...types: JobType[]): Promise<{
  75. [index: string]: number;
  76. }>;
  77. /**
  78. * Get current job state.
  79. *
  80. * @param jobId - job identifier.
  81. * @returns Returns one of these values:
  82. * 'completed', 'failed', 'delayed', 'active', 'waiting', 'waiting-children', 'unknown'.
  83. */
  84. getJobState(jobId: string): Promise<JobState | 'unknown'>;
  85. /**
  86. * Get global queue configuration.
  87. *
  88. * @returns Returns the global queue configuration.
  89. */
  90. getMeta(): Promise<QueueMeta>;
  91. /**
  92. * @returns Returns the number of jobs in completed status.
  93. */
  94. getCompletedCount(): Promise<number>;
  95. /**
  96. * Returns the number of jobs in failed status.
  97. */
  98. getFailedCount(): Promise<number>;
  99. /**
  100. * Returns the number of jobs in delayed status.
  101. */
  102. getDelayedCount(): Promise<number>;
  103. /**
  104. * Returns the number of jobs in active status.
  105. */
  106. getActiveCount(): Promise<number>;
  107. /**
  108. * Returns the number of jobs in prioritized status.
  109. */
  110. getPrioritizedCount(): Promise<number>;
  111. /**
  112. * Returns the number of jobs per priority.
  113. */
  114. getCountsPerPriority(priorities: number[]): Promise<{
  115. [index: string]: number;
  116. }>;
  117. /**
  118. * Returns the number of jobs in waiting or paused statuses.
  119. */
  120. getWaitingCount(): Promise<number>;
  121. /**
  122. * Returns the number of jobs in waiting-children status.
  123. */
  124. getWaitingChildrenCount(): Promise<number>;
  125. /**
  126. * Returns the jobs that are in the "waiting" status.
  127. * @param start - zero based index from where to start returning jobs.
  128. * @param end - zero based index where to stop returning jobs.
  129. */
  130. getWaiting(start?: number, end?: number): Promise<JobBase[]>;
  131. /**
  132. * Returns the jobs that are in the "waiting-children" status.
  133. * I.E. parent jobs that have at least one child that has not completed yet.
  134. * @param start - zero based index from where to start returning jobs.
  135. * @param end - zero based index where to stop returning jobs.
  136. */
  137. getWaitingChildren(start?: number, end?: number): Promise<JobBase[]>;
  138. /**
  139. * Returns the jobs that are in the "active" status.
  140. * @param start - zero based index from where to start returning jobs.
  141. * @param end - zero based index where to stop returning jobs.
  142. */
  143. getActive(start?: number, end?: number): Promise<JobBase[]>;
  144. /**
  145. * Returns the jobs that are in the "delayed" status.
  146. * @param start - zero based index from where to start returning jobs.
  147. * @param end - zero based index where to stop returning jobs.
  148. */
  149. getDelayed(start?: number, end?: number): Promise<JobBase[]>;
  150. /**
  151. * Returns the jobs that are in the "prioritized" status.
  152. * @param start - zero based index from where to start returning jobs.
  153. * @param end - zero based index where to stop returning jobs.
  154. */
  155. getPrioritized(start?: number, end?: number): Promise<JobBase[]>;
  156. /**
  157. * Returns the jobs that are in the "completed" status.
  158. * @param start - zero based index from where to start returning jobs.
  159. * @param end - zero based index where to stop returning jobs.
  160. */
  161. getCompleted(start?: number, end?: number): Promise<JobBase[]>;
  162. /**
  163. * Returns the jobs that are in the "failed" status.
  164. * @param start - zero based index from where to start returning jobs.
  165. * @param end - zero based index where to stop returning jobs.
  166. */
  167. getFailed(start?: number, end?: number): Promise<JobBase[]>;
  168. /**
  169. * Returns the qualified job ids and the raw job data (if available) of the
  170. * children jobs of the given parent job.
  171. * It is possible to get either the already processed children, in this case
  172. * an array of qualified job ids and their result values will be returned,
  173. * or the pending children, in this case an array of qualified job ids will
  174. * be returned.
  175. * A qualified job id is a string representing the job id in a given queue,
  176. * for example: "bull:myqueue:jobid".
  177. *
  178. * @param parentId - The id of the parent job
  179. * @param type - "processed" | "pending"
  180. * @param opts - Options for the query.
  181. *
  182. * @returns an object with the following shape:
  183. * `{ items: { id: string, v?: any, err?: string } [], jobs: JobJsonRaw[], total: number}`
  184. */
  185. getDependencies(parentId: string, type: 'processed' | 'pending', start: number, end: number): Promise<{
  186. items: {
  187. id: string;
  188. v?: any;
  189. err?: string;
  190. }[];
  191. jobs: JobJsonRaw[];
  192. total: number;
  193. }>;
  194. getRanges(types: JobType[], start?: number, end?: number, asc?: boolean): Promise<string[]>;
  195. /**
  196. * Returns the jobs that are on the given statuses (note that JobType is synonym for job status)
  197. * @param types - the statuses of the jobs to return.
  198. * @param start - zero based index from where to start returning jobs.
  199. * @param end - zero based index where to stop returning jobs.
  200. * @param asc - if true, the jobs will be returned in ascending order.
  201. */
  202. getJobs(types?: JobType[] | JobType, start?: number, end?: number, asc?: boolean): Promise<JobBase[]>;
  203. /**
  204. * Returns the logs for a given Job.
  205. * @param jobId - the id of the job to get the logs for.
  206. * @param start - zero based index from where to start returning jobs.
  207. * @param end - zero based index where to stop returning jobs.
  208. * @param asc - if true, the jobs will be returned in ascending order.
  209. */
  210. getJobLogs(jobId: string, start?: number, end?: number, asc?: boolean): Promise<{
  211. logs: string[];
  212. count: number;
  213. }>;
  214. private baseGetClients;
  215. /**
  216. * Get the worker list related to the queue. i.e. all the known
  217. * workers that are available to process jobs for this queue.
  218. * Note: GCP does not support SETNAME, so this call will not work
  219. *
  220. * @returns - Returns an array with workers info.
  221. */
  222. getWorkers(): Promise<{
  223. [index: string]: string;
  224. }[]>;
  225. /**
  226. * Returns the current count of workers for the queue.
  227. *
  228. * getWorkersCount(): Promise<number>
  229. *
  230. */
  231. getWorkersCount(): Promise<number>;
  232. /**
  233. * Get queue events list related to the queue.
  234. * Note: GCP does not support SETNAME, so this call will not work
  235. *
  236. * @deprecated do not use this method, it will be removed in the future.
  237. *
  238. * @returns - Returns an array with queue events info.
  239. */
  240. getQueueEvents(): Promise<{
  241. [index: string]: string;
  242. }[]>;
  243. /**
  244. * Get queue metrics related to the queue.
  245. *
  246. * This method returns the gathered metrics for the queue.
  247. * The metrics are represented as an array of job counts
  248. * per unit of time (1 minute).
  249. *
  250. * @param start - Start point of the metrics, where 0
  251. * is the newest point to be returned.
  252. * @param end - End point of the metrics, where -1 is the
  253. * oldest point to be returned.
  254. *
  255. * @returns - Returns an object with queue metrics.
  256. */
  257. getMetrics(type: 'completed' | 'failed', start?: number, end?: number): Promise<Metrics>;
  258. private parseClientList;
  259. /**
  260. * Export the metrics for the queue in the Prometheus format.
  261. * Automatically exports all the counts returned by getJobCounts().
  262. *
  263. * @returns - Returns a string with the metrics in the Prometheus format.
  264. *
  265. * @see {@link https://prometheus.io/docs/instrumenting/exposition_formats/}
  266. *
  267. **/
  268. exportPrometheusMetrics(globalVariables?: Record<string, string>): Promise<string>;
  269. }