1
- import { CONSTANTS } from "@core/constants " ;
1
+ import { GetPrefixedQueue } from "@core/helpers " ;
2
2
import { IClientConnector } from "@core/types" ;
3
3
/**
4
4
* AbstractProducer is an abstract class that provides basic functionalities for adding data to queues.
@@ -12,7 +12,7 @@ export default abstract class AbstractProducer<K> {
12
12
* @param client - An instance of IClientConnector to interact with the queue.
13
13
*/
14
14
constructor ( private name : string , private client : IClientConnector < K > ) {
15
- this . queueName = CONSTANTS . QUEUE_PREFIX + this . name ;
15
+ this . queueName = GetPrefixedQueue ( this . name ) ;
16
16
process . once ( "SIGINT" , this . handleShutdown . bind ( this ) ) ;
17
17
process . once ( "SIGTERM" , this . handleShutdown . bind ( this ) ) ;
18
18
}
@@ -21,14 +21,23 @@ export default abstract class AbstractProducer<K> {
21
21
* Adds data to the main queue and optionally to additional queues atomically.
22
22
* @param data - The data to be added to the queue.
23
23
* @param additionalQueues - Optional. Additional queues to which the data should be added atomically.
24
- * @returns A promise that resolves when the data has been added.
24
+ * @returns A promise that resolves to the job ID(s) when the data has been added.
25
+ * If data is added to a single queue, it returns a string representing the job ID.
26
+ * If data is added to multiple queues, it returns an array of strings representing the jobs IDs.
25
27
*/
26
- public async add ( data : unknown , additionalQueues ?: string [ ] ) {
28
+ public async add (
29
+ data : unknown ,
30
+ additionalQueues ?: string [ ]
31
+ ) : Promise < string | string [ ] > {
32
+ const stringifiedData = JSON . stringify ( data ) ;
27
33
if ( additionalQueues && additionalQueues . length ) {
28
- await this . client . addAtomic ( this . queueName , additionalQueues , data ) ;
29
- return ;
34
+ return await this . client . addAtomic (
35
+ this . queueName ,
36
+ additionalQueues ,
37
+ stringifiedData
38
+ ) ;
30
39
}
31
- await this . client . add ( this . queueName , data ) ;
40
+ return await this . client . add ( this . queueName , stringifiedData ) ;
32
41
}
33
42
34
43
/**
0 commit comments