From e0fe7d0381b394d54e7c769b11b861361166525d Mon Sep 17 00:00:00 2001 From: Nevo David Date: Sat, 9 Aug 2025 01:28:24 +0700 Subject: [PATCH] feat: expiration --- .../helpers/src/utils/concurrency.service.ts | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/libraries/helpers/src/utils/concurrency.service.ts b/libraries/helpers/src/utils/concurrency.service.ts index 906e5f52..ce2065ae 100644 --- a/libraries/helpers/src/utils/concurrency.service.ts +++ b/libraries/helpers/src/utils/concurrency.service.ts @@ -1,6 +1,7 @@ import { ioRedis } from '@gitroom/nestjs-libraries/redis/redis.service'; import Bottleneck from 'bottleneck'; import { timer } from '@gitroom/helpers/utils/timer'; +import { BadBody } from '@gitroom/nestjs-libraries/integrations/social.abstract'; const connection = new Bottleneck.IORedisConnection({ client: ioRedis, @@ -23,19 +24,28 @@ export const concurrency = async ( minTime: 1000, }); let load: T; + + if (ignoreConcurrency) { + return await func(); + } + try { - if (ignoreConcurrency) { - return await func(); - } load = await mapper[strippedIdentifier].schedule( - { expiration: 600000 }, + { expiration: 10000 }, async () => { try { return await func(); } catch (err) {} } ); - } catch (err) {} + } catch (err) { + throw new BadBody( + identifier, + JSON.stringify({}), + {} as any, + `Something is wrong with ${identifier}` + ); + } return load; };