Skip to content

Commit

Permalink
Add setQueueRateLimit
Browse files Browse the repository at this point in the history
  • Loading branch information
jasrusable committed Jun 28, 2020
1 parent 7e094a9 commit 56b25c0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/actions/set-queue-rate-limit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Redis } from 'ioredis';
import { set } from '../utils/redis';
import { getQueueRateLimitKey } from '../utils/keys';

export const setQueueRateLimit = async ({
amount,
interval,
queue,
client,
}: {
amount: number;
interval: number;
queue: string;
client: Redis;
}) => {
await set({
key: getQueueRateLimitKey({ queue }),
value: JSON.stringify({ amount, interval }),
client,
});
};
4 changes: 4 additions & 0 deletions src/utils/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
Data structure keys:
*/

export const getQueueRateLimitKey = ({ queue }: { queue: string }) => {
return `${queue}:rate-limit`;
};

export const getQueuePausedKey = ({ queue }: { queue: string }) => {
return `${queue}:is-paused`;
};
Expand Down

0 comments on commit 56b25c0

Please sign in to comment.