Skip to content

Commit

Permalink
timeout for consume job
Browse files Browse the repository at this point in the history
  • Loading branch information
clairton committed May 27, 2024
1 parent 3c3a669 commit 659539f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ CLEAN_CONFIG_ON_DISCONNECT=true to clean all saved redis configurations on disco
CONFIG_SESSION_PHONE_CLIENT=Unoapi Name that will be displayed on smartphone connection
CONFIG_SESSION_PHONE_NAME=Chrome Browser Name = Chrome | Firefox | Edge | Opera | Safari
WHATSAPP_VERSION=Version of whatsapp, default is [2, 2413, 1]
CONSUMER_TIMEOUT_MS=miliseconds in timeout for consume job, default is 5000
```

Bucket env to config assets media compatible with S3, this config can't save in redis:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "unoapi-cloud",
"version": "1.15.56",
"version": "1.15.57",
"description": "Unoapi Cloud",
"exports": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
4 changes: 4 additions & 0 deletions src/amqp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
UNOAPI_JOB_NOTIFICATION,
IGNORED_CONNECTIONS_NUMBERS,
VALIDATE_ROUTING_KEY,
CONSUMER_TIMEOUT_MS,
} from './defaults'
import logger from './services/logger'
import { version } from '../package.json'
Expand Down Expand Up @@ -187,6 +188,7 @@ export const amqpConsume = async (
if (!payload) {
throw `payload not be null `
}
const timeoutId = setTimeout(() => { throw new Error('timeout consume') }, CONSUMER_TIMEOUT_MS)
const content: string = payload.content.toString()
const phone = payload.fields.routingKey
const data = JSON.parse(content)
Expand Down Expand Up @@ -232,6 +234,8 @@ export const amqpConsume = async (
await amqpEnqueue(queue, phone, data, { delay: UNOAPI_MESSAGE_RETRY_DELAY * countRetries, maxRetries, countRetries })
}
await channel.ack(payload)
} finally {
clearTimeout(timeoutId)
}
}

Expand Down
1 change: 1 addition & 0 deletions src/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const WEBHOOK_URL = process.env.WEBHOOK_URL || 'http://localhost:6789/web
export const WEBHOOK_HEADER = process.env.WEBHOOK_HEADER || 'Authorization'
export const WEBHOOK_TOKEN = process.env.WEBHOOK_TOKEN || '123abc'
export const WEBHOOK_TIMEOUT_MS = parseInt(process.env.WEBHOOK_TIMEOUT_MS || '5000')
export const CONSUMER_TIMEOUT_MS = parseInt(process.env.CONSUMER_TIMEOUT_MS || '5000')
export const WEBHOOK_SEND_NEW_MESSAGES = process.env.WEBHOOK_SEND_NEW_MESSAGES == _undefined ? false : process.env.WEBHOOK_SEND_NEW_MESSAGES == 'true'
export const WEBHOOK_SESSION = process.env.WEBHOOK_SESSION || ''
export const AMQP_URL = process.env.AMQP_URL || 'amqp://guest:guest@localhost:5672'
Expand Down

0 comments on commit 659539f

Please sign in to comment.