minimal-job.d.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import { JobsOptions } from '../types/job-options';
  2. import { JobProgress } from '../types/job-progress';
  3. import { JobJsonSandbox } from '../types/job-json-sandbox';
  4. import { JobJson } from './job-json';
  5. import { ParentKeys } from './parent';
  6. import { ParentOptions } from './parent-options';
  7. export type BulkJobOptions = Omit<JobsOptions, 'repeat'>;
  8. export interface MoveToDelayedOpts {
  9. skipAttempt?: boolean;
  10. fieldsToUpdate?: Record<string, any>;
  11. fetchNext?: boolean;
  12. }
  13. export interface RetryJobOpts {
  14. fieldsToUpdate?: Record<string, any>;
  15. }
  16. export interface MoveToWaitingChildrenOpts {
  17. child?: ParentOptions;
  18. }
  19. export interface DependencyOpts {
  20. /**
  21. * Cursor value to be passed for pagination
  22. */
  23. cursor?: number;
  24. /**
  25. * Max quantity of jobs to be retrieved
  26. */
  27. count?: number;
  28. }
  29. export interface DependenciesOpts {
  30. /**
  31. * Options for failed child pagination
  32. */
  33. failed?: DependencyOpts;
  34. /**
  35. * Options for ignored child pagination
  36. */
  37. ignored?: DependencyOpts;
  38. /**
  39. * Options for processed child pagination
  40. */
  41. processed?: DependencyOpts;
  42. /**
  43. * Options for unprocessed child pagination
  44. */
  45. unprocessed?: DependencyOpts;
  46. }
  47. /**
  48. * MinimalJob
  49. */
  50. export interface MinimalJob<DataType = any, ReturnType = any, NameType extends string = string> {
  51. /**
  52. * The name of the Job
  53. */
  54. name: NameType;
  55. /**
  56. * The payload for this job.
  57. */
  58. data: DataType;
  59. /**
  60. * The options object for this job.
  61. */
  62. opts: JobsOptions;
  63. id?: string;
  64. /**
  65. * The progress a job has performed so far.
  66. * @defaultValue 0
  67. */
  68. progress: JobProgress;
  69. /**
  70. * The value returned by the processor when processing this job.
  71. * @defaultValue null
  72. */
  73. returnvalue: ReturnType;
  74. /**
  75. * Stacktrace for the error (for failed jobs).
  76. * @defaultValue null
  77. */
  78. stacktrace: string[];
  79. /**
  80. * An amount of milliseconds to wait until this job can be processed.
  81. * @defaultValue 0
  82. */
  83. delay: number;
  84. /**
  85. * Timestamp when the job was created (unless overridden with job options).
  86. */
  87. timestamp: number;
  88. /**
  89. * Number of attempts after the job has failed.
  90. * @defaultValue 0
  91. */
  92. attemptsMade: number;
  93. /**
  94. * Reason for failing.
  95. */
  96. failedReason: string;
  97. /**
  98. * Timestamp for when the job finished (completed or failed).
  99. */
  100. finishedOn?: number;
  101. /**
  102. * Timestamp for when the job was processed.
  103. */
  104. processedOn?: number;
  105. /**
  106. * Fully qualified key (including the queue prefix) pointing to the parent of this job.
  107. */
  108. parentKey?: string;
  109. /**
  110. * Object that contains parentId (id) and parent queueKey.
  111. */
  112. parent?: ParentKeys;
  113. /**
  114. * Base repeat job key.
  115. */
  116. repeatJobKey?: string;
  117. /**
  118. * Prepares a job to be serialized for storage in Redis.
  119. * @returns
  120. */
  121. asJSON(): JobJson;
  122. /**
  123. * Prepares a job to be passed to Sandbox.
  124. * @returns
  125. */
  126. asJSONSandbox(): JobJsonSandbox;
  127. /**
  128. * Updates a job's data
  129. *
  130. * @param data - the data that will replace the current jobs data.
  131. */
  132. updateData(data: DataType): Promise<void>;
  133. /**
  134. * Updates a job's progress
  135. *
  136. * @param progress - number or object to be saved as progress.
  137. */
  138. updateProgress(progress: JobProgress): Promise<void>;
  139. /**
  140. * Logs one row of log data.
  141. *
  142. * @param logRow - string with log data to be logged.
  143. */
  144. log(logRow: string): Promise<number>;
  145. get queueName(): string;
  146. /**
  147. * @returns the prefix that is used.
  148. */
  149. get prefix(): string;
  150. /**
  151. * @returns it includes the prefix, the namespace separator :, and queue name.
  152. * @see https://www.gnu.org/software/gawk/manual/html_node/Qualified-Names.html
  153. */
  154. get queueQualifiedName(): string;
  155. }