Skip to content

Commit

Permalink
refactor(Message)!: remove Message.MessagePriority, add EMessagePriority
Browse files Browse the repository at this point in the history
  • Loading branch information
weyoss committed Dec 11, 2023
1 parent 29e8817 commit 702a01d
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 38 deletions.
19 changes: 6 additions & 13 deletions src/lib/message/message-envelope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import { parseExpression } from 'cron-parser';
import {
EMessagePriority,
EMessagePropertyStatus,
IMessageSerialized,
IQueueParams,
Expand All @@ -28,17 +29,6 @@ import { ExchangeFanOut } from '../exchange/exchange-fan-out';
import { ExchangeTopic } from '../exchange/exchange-topic';

export class MessageEnvelope {
static readonly MessagePriority = {
LOWEST: 7,
VERY_LOW: 6,
LOW: 5,
NORMAL: 4,
ABOVE_NORMAL: 3,
HIGH: 2,
VERY_HIGH: 1,
HIGHEST: 0,
};

protected static defaultConsumeOptions: TMessageConsumeOptions = {
ttl: 0,
retryThreshold: 3,
Expand All @@ -58,7 +48,7 @@ export class MessageEnvelope {

protected body: unknown = null;

protected priority: number | null = null;
protected priority: EMessagePriority | null = null;

protected scheduledCron: string | null = null;

Expand Down Expand Up @@ -262,7 +252,10 @@ export class MessageEnvelope {
}

setPriority(priority: number): MessageEnvelope {
if (!Object.values(MessageEnvelope.MessagePriority).includes(priority)) {
if (
priority < EMessagePriority.HIGHEST ||
priority > EMessagePriority.LOWEST
) {
throw new MessageError('Invalid message priority.');
}
this.priority = priority;
Expand Down
1 change: 0 additions & 1 deletion src/lib/queue/errors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ export { QueueNotEmptyError } from './queue-not-empty.error';
export { QueueNotFoundError } from './queue-not-found.error';
export { QueueRateLimitError } from './queue-rate-limit.error';
export { QueueError } from './queue.error';
export { QueueDeleteOperationError } from './queue-delete-operation.error';
12 changes: 0 additions & 12 deletions src/lib/queue/errors/queue-delete-operation.error.ts

This file was deleted.

12 changes: 0 additions & 12 deletions src/lib/queue/errors/queue-message-not-found.error.ts

This file was deleted.

11 changes: 11 additions & 0 deletions types/message/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@
import { TExchangeSerialized } from '../index';
import { IQueueParams } from '../queue';

export enum EMessagePriority {
HIGHEST,
VERY_HIGH,
HIGH,
ABOVE_NORMAL,
NORMAL,
LOW,
VERY_LOW,
LOWEST,
}

export enum EMessageProperty {
ID,
STATUS,
Expand Down

0 comments on commit 702a01d

Please sign in to comment.