Skip to content

Commit 28b6921

Browse files
Sleep if timeout is hit during default attachments processing (#40)
## Summary This pull request introduces a minor version update to the library and adds a new utility for handling timeouts, which is integrated into the `WorkerAdapter` class. This mitigates the issue of lambda timing out. The most important changes include the addition of a `sleep` function and a default sleep delay constant, as well as their usage in the `WorkerAdapter` to handle timeouts. ## Related Issues - work-item: https://app.devrev.ai/devrev/works/ISS-179204 ## Type of Change - [x] Change doesn't affect products or customers - [x] Bug fix (non-breaking change which fixes an issue) - [ ] Non-breaking change (the new functionality and code refactor do not require a migration strategy) - [ ] Breaking change (fix or feature that will require a migration plan for data or other services) - [ ] Documentation/comment update - [ ] Other (please describe): ## Testing Procedure - Run any ADaaS snap-in where you experience problems with lambda timeout-ing during attachments extraction, using this library version: 1.5.1 ## Checklist - [x] I used generative AI to generate this PR - [x] I have self-reviewed my code for clarity and correctness - [ ] I have added or updated comments for complex or non-obvious logic in my code - [ ] I have updated relevant documentation (e.g., README, code docs) - [x] My changes do not introduce new warnings or errors - [ ] I have added or updated tests to cover new or changed functionality - [x] All tests pass locally with my changes applied
1 parent 77b2cdb commit 28b6921

File tree

5 files changed

+18
-3
lines changed

5 files changed

+18
-3
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devrev/ts-adaas",
3-
"version": "1.5.0",
3+
"version": "1.5.1",
44
"description": "Typescript library containing the ADaaS(AirDrop as a Service) control protocol.",
55
"type": "commonjs",
66
"main": "./dist/index.js",

src/common/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,5 @@ export const AIRDROP_DEFAULT_ITEM_TYPES = {
4343
};
4444

4545
export const LIBRARY_VERSION = getLibraryVersion();
46+
47+
export const DEFAULT_SLEEP_DELAY_MS = 180000; // 3 minutes

src/common/helpers.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,8 @@ export function getLibraryVersion() {
194194
return '';
195195
}
196196
}
197+
198+
export function sleep(ms: number) {
199+
console.log(`Sleeping for ${ms}ms.`);
200+
return new Promise((resolve) => setTimeout(resolve, ms));
201+
}

src/workers/worker-adapter.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
AIRDROP_DEFAULT_ITEM_TYPES,
2626
ALLOWED_EXTRACTION_EVENT_TYPES,
2727
STATELESS_EVENT_TYPES,
28+
DEFAULT_SLEEP_DELAY_MS,
2829
} from '../common/constants';
2930
import { State } from '../state/state';
3031
import { WorkerAdapterInterface, WorkerAdapterOptions } from '../types/workers';
@@ -46,6 +47,7 @@ import { Mappers } from '../mappers/mappers';
4647
import { Uploader } from '../uploader/uploader';
4748
import { serializeAxiosError } from '../logger/logger';
4849
import { SyncMapperRecordStatus } from '../mappers/mappers.interface';
50+
import { sleep } from '../common/helpers';
4951

5052
export function createWorkerAdapter<ConnectorState>({
5153
event,
@@ -877,6 +879,12 @@ export class WorkerAdapter<ConnectorState> {
877879

878880
// Loop through the batches of attachments
879881
for (let i = lastProcessedBatchIndex; i < reducedAttachments.length; i++) {
882+
883+
// Check if we hit timeout
884+
if (adapter.isTimeout) {
885+
await sleep(DEFAULT_SLEEP_DELAY_MS);
886+
}
887+
880888
const attachmentsBatch = reducedAttachments[i];
881889

882890
// Create a list of promises for parallel processing

0 commit comments

Comments
 (0)