Skip to content

Commit

Permalink
Add namespace to queues names for external services (#7246)
Browse files Browse the repository at this point in the history
* Add namespace to queues names for external services

* Fix unit tests to support namespace in queues names for external services
  • Loading branch information
gabriel-piles authored and RafaPolit committed Sep 23, 2024
1 parent 93c8c9b commit 9e6f7bd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ describe('convertToPdfWorker', () => {

const recreateRedisQueue = async () => {
try {
await redisSMQ.deleteQueueAsync({ qname: 'convert-to-pdf_results' });
await redisSMQ.deleteQueueAsync({ qname: 'development_convert-to-pdf_results' });
} catch (err) {
if (err instanceof Error && err.name !== 'queueNotFound') {
throw err;
}
}
await redisSMQ.createQueueAsync({ qname: 'convert-to-pdf_results' });
await redisSMQ.createQueueAsync({ qname: 'development_convert-to-pdf_results' });
};

beforeAll(async () => {
Expand Down Expand Up @@ -88,7 +88,7 @@ describe('convertToPdfWorker', () => {
};

await redisSMQ.sendMessageAsync({
qname: 'convert-to-pdf_results',
qname: 'development_convert-to-pdf_results',
message: JSON.stringify(message),
});
});
Expand Down Expand Up @@ -162,7 +162,7 @@ describe('convertToPdfWorker', () => {
jest.spyOn(handleError, 'handleError').mockImplementationOnce(() => {});

await redisSMQ.sendMessageAsync({
qname: 'convert-to-pdf_results',
qname: 'development_convert-to-pdf_results',
message: JSON.stringify(message),
});

Expand Down
4 changes: 2 additions & 2 deletions app/api/services/tasksmanager/TaskManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ export class TaskManager<

constructor(service: Service<T, R>) {
this.service = service;
this.taskQueue = `${service.serviceName}_tasks`;
this.resultsQueue = `${service.serviceName}_results`;
this.taskQueue = `${config.ENVIRONMENT}_${service.serviceName}_tasks`;
this.resultsQueue = `${config.ENVIRONMENT}_${service.serviceName}_results`;
const redisUrl = `redis://${config.redis.host}:${config.redis.port}`;
this.redisClient = Redis.createClient(redisUrl);
this.redisSMQ = new RedisSMQ({ client: this.redisClient });
Expand Down
14 changes: 7 additions & 7 deletions app/api/services/tasksmanager/specs/ExternalDummyService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,16 @@ export class ExternalDummyService {
}

async resetQueue() {
await this.deleteQueue(`${this.serviceName}_tasks`);
await this.deleteQueue(`${this.serviceName}_results`);
await this.deleteQueue(`development_${this.serviceName}_tasks`);
await this.deleteQueue(`development_${this.serviceName}_results`);

await this.createQueue(`${this.serviceName}_tasks`);
await this.createQueue(`${this.serviceName}_results`);
await this.createQueue(`development_${this.serviceName}_tasks`);
await this.createQueue(`development_${this.serviceName}_results`);
}

async readFirstTaskMessage() {
const message: RedisSMQ.QueueMessage | {} = await this.rsmq.receiveMessageAsync({
qname: `${this.serviceName}_tasks`,
qname: `development_${this.serviceName}_tasks`,
});
const queueMessage = message as QueueMessage;

Expand All @@ -140,7 +140,7 @@ export class ExternalDummyService {
}

await this.rsmq.deleteMessageAsync({
qname: `${this.serviceName}_tasks`,
qname: `development_${this.serviceName}_tasks`,
id: queueMessage.id,
});

Expand Down Expand Up @@ -186,7 +186,7 @@ export class ExternalDummyService {
async sendFinishedMessage(task: ResultsMessage) {
try {
await this.rsmq.sendMessageAsync({
qname: `${this.serviceName}_results`,
qname: `development_${this.serviceName}_results`,
message: JSON.stringify(task),
});
} catch (err) {
Expand Down

0 comments on commit 9e6f7bd

Please sign in to comment.