diff --git a/README.md b/README.md index ab6bd2ac..62870b7a 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/package.json b/package.json index 1b3b0f5f..81188bb2 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/amqp.ts b/src/amqp.ts index 0e55d880..9d6fa218 100644 --- a/src/amqp.ts +++ b/src/amqp.ts @@ -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' @@ -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) @@ -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) } } diff --git a/src/defaults.ts b/src/defaults.ts index cf48cce7..35404a4e 100644 --- a/src/defaults.ts +++ b/src/defaults.ts @@ -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'