Skip to content

Commit

Permalink
hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
silaselisha committed Dec 25, 2023
1 parent f696760 commit e6a45f8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const start = async (): Promise<void> => {
})

await client.connect()

cloudinary.config({
secure: true,
cloud_name: process.env.CLOUDINARY_NAME,
Expand Down
7 changes: 4 additions & 3 deletions src/workers/redis-rlm-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,16 @@ export const rateLimiterRefillBucketToken = async (): Promise<void> => {
parentPort?.postMessage(`elapsed time since last refill: ${timeElapsedOnFullBucket}`)

if (counter > 0) {
const tokens = counter
const message = tokens > 1 ? 'tokens' : 'token'
parentPort?.postMessage(`${tokens} ${message} to add in your bucket`)

for (let i = 1; i <= currBucketSize; i++) {
const token = await client.HGETALL(`token-${i}`)
const tokens: number = counter

const timeElapsed = Math.floor((Math.floor(Date.now() / 1000) - parseInt(token?.timestamp, 10)))

parentPort?.postMessage(`refill time in seconds: ${REFILL_TIME}`)
parentPort?.postMessage(`${token.name} elapsed time: ${timeElapsed}`)
parentPort?.postMessage(`${tokens} token to add in your bucket`)

if (token.isActive === 'false' && timeElapsed >= REFILL_TIME) {
parentPort?.postMessage(`${token.name} now active to use`)
Expand Down

0 comments on commit e6a45f8

Please sign in to comment.