Skip to content

Commit

Permalink
increase consumer timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
clairton committed May 27, 2024
1 parent 659539f commit 492db32
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +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
CONSUMER_TIMEOUT_MS=miliseconds in timeout for consume job, default is 30000
```

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.57",
"version": "1.15.58",
"description": "Unoapi Cloud",
"exports": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions src/amqp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +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 timeoutId = setTimeout(() => { throw new Error(`timeout ${CONSUMER_TIMEOUT_MS} is exceeded consume queue: ${queue}, phone: ${phone}`) }, CONSUMER_TIMEOUT_MS)
const content: string = payload.content.toString()
const phone = payload.fields.routingKey
const data = JSON.parse(content)
Expand All @@ -204,6 +204,7 @@ export const amqpConsume = async (
}
logger.debug('Ack message!')
await channel.ack(payload)
clearTimeout(timeoutId)
} catch (error) {
logger.error(error)
if (countRetries >= maxRetries) {
Expand Down Expand Up @@ -234,7 +235,6 @@ 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
8 changes: 4 additions & 4 deletions src/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ 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 CONSUMER_TIMEOUT_MS = parseInt(process.env.CONSUMER_TIMEOUT_MS || '30000')
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'
export const REDIS_URL = process.env.REDIS_URL || 'redis://localhost:6379'
export const PROXY_URL = process.env.PROXY_URL

// behavior of unoapi
export const CONNECTION_TIMEOUT = process.env.CONNECTION_TIMEOUT || 140_000
export const CONNECTION_TIMEOUT = parseInt(process.env.CONNECTION_TIMEOUT || '140000')
export const UNOAPI_RETRY_REQUEST_DELAY_MS = parseInt(process.env.UNOAPI_RETRY_REQUEST_DELAY || process.env.UNOAPI_RETRY_REQUEST_DELAY_MS || '5000')
export const QR_TIMEOUT = process.env.QR_TIMEOUT || 30_000
export const SLEEP_TIME = process.env.SLEEP_TIME || 500
export const QR_TIMEOUT = parseInt(process.env.QR_TIMEOUT || '30000')
export const SLEEP_TIME = parseInt(process.env.SLEEP_TIME || '5000')
export const MAX_QRCODE_GENERATE = process.env.MAX_QRCODE_GENERATE || 6
export const DATA_TTL: number = parseInt(process.env.DATA_TTL || `${60 * 60 * 24 * 30}`) // a month
export const DATA_JID_TTL: number = parseInt(process.env.DATA_JID_TTL || `${60 * 60 * 24 * 7}`) // a week
Expand Down

0 comments on commit 492db32

Please sign in to comment.