queue-base.d.ts 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { EventEmitter } from 'events';
  2. import { MinimalQueue, QueueBaseOptions, RedisClient, Span } from '../interfaces';
  3. import { RedisConnection } from './redis-connection';
  4. import { Job } from './job';
  5. import { KeysMap } from './queue-keys';
  6. import { Scripts } from './scripts';
  7. import { SpanKind } from '../enums';
  8. import { DatabaseType } from '../types/database-type';
  9. /**
  10. * Base class for all classes that need to interact with queues.
  11. * This class is normally not used directly, but extended by the other classes.
  12. *
  13. */
  14. export declare class QueueBase extends EventEmitter implements MinimalQueue {
  15. readonly name: string;
  16. opts: QueueBaseOptions;
  17. toKey: (type: string) => string;
  18. keys: KeysMap;
  19. closing: Promise<void> | undefined;
  20. protected closed: boolean;
  21. protected hasBlockingConnection: boolean;
  22. protected scripts: Scripts;
  23. protected connection: RedisConnection;
  24. readonly qualifiedName: string;
  25. /**
  26. *
  27. * @param name - The name of the queue.
  28. * @param opts - Options for the queue.
  29. * @param Connection - An optional "Connection" class used to instantiate a Connection. This is useful for
  30. * testing with mockups and/or extending the Connection class and passing an alternate implementation.
  31. */
  32. constructor(name: string, opts?: QueueBaseOptions, Connection?: typeof RedisConnection, hasBlockingConnection?: boolean);
  33. /**
  34. * Returns a promise that resolves to a redis client. Normally used only by subclasses.
  35. */
  36. get client(): Promise<RedisClient>;
  37. protected createScripts(): void;
  38. /**
  39. * Returns the version of the Redis instance the client is connected to,
  40. */
  41. get redisVersion(): string;
  42. /**
  43. * Returns the database type of the Redis instance the client is connected to,
  44. */
  45. get databaseType(): DatabaseType;
  46. /**
  47. * Helper to easily extend Job class calls.
  48. */
  49. protected get Job(): typeof Job;
  50. /**
  51. * Emits an event. Normally used by subclasses to emit events.
  52. *
  53. * @param event - The emitted event.
  54. * @param args -
  55. * @returns
  56. */
  57. emit(event: string | symbol, ...args: any[]): boolean;
  58. waitUntilReady(): Promise<RedisClient>;
  59. protected base64Name(): string;
  60. protected clientName(suffix?: string): string;
  61. /**
  62. *
  63. * Closes the connection and returns a promise that resolves when the connection is closed.
  64. */
  65. close(): Promise<void>;
  66. /**
  67. *
  68. * Force disconnects a connection.
  69. */
  70. disconnect(): Promise<void>;
  71. protected checkConnectionError<T>(fn: () => Promise<T>, delayInMs?: number): Promise<T | undefined>;
  72. /**
  73. * Wraps the code with telemetry and provides a span for configuration.
  74. *
  75. * @param spanKind - kind of the span: Producer, Consumer, Internal
  76. * @param operation - operation name (such as add, process, etc)
  77. * @param destination - destination name (normally the queue name)
  78. * @param callback - code to wrap with telemetry
  79. * @param srcPropagationMetadata -
  80. * @returns
  81. */
  82. trace<T>(spanKind: SpanKind, operation: string, destination: string, callback: (span?: Span, dstPropagationMetadata?: string) => Promise<T> | T, srcPropagationMetadata?: string): Promise<T | Promise<T>>;
  83. }