Skip to content

Sleep if timeout is hit during default attachments processing #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@devrev/ts-adaas",
"version": "1.5.0",
"version": "1.5.1",
"description": "Typescript library containing the ADaaS(AirDrop as a Service) control protocol.",
"type": "commonjs",
"main": "./dist/index.js",
Expand Down
2 changes: 2 additions & 0 deletions src/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@ export const AIRDROP_DEFAULT_ITEM_TYPES = {
};

export const LIBRARY_VERSION = getLibraryVersion();

export const DEFAULT_SLEEP_DELAY_MS = 180000; // 3 minutes
5 changes: 5 additions & 0 deletions src/common/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,8 @@ export function getLibraryVersion() {
return '';
}
}

export function sleep(ms: number) {
console.log(`Sleeping for ${ms}ms.`);
return new Promise((resolve) => setTimeout(resolve, ms));
}
8 changes: 8 additions & 0 deletions src/workers/worker-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
AIRDROP_DEFAULT_ITEM_TYPES,
ALLOWED_EXTRACTION_EVENT_TYPES,
STATELESS_EVENT_TYPES,
DEFAULT_SLEEP_DELAY_MS,
} from '../common/constants';
import { State } from '../state/state';
import { WorkerAdapterInterface, WorkerAdapterOptions } from '../types/workers';
Expand All @@ -46,6 +47,7 @@ import { Mappers } from '../mappers/mappers';
import { Uploader } from '../uploader/uploader';
import { serializeAxiosError } from '../logger/logger';
import { SyncMapperRecordStatus } from '../mappers/mappers.interface';
import { sleep } from '../common/helpers';

export function createWorkerAdapter<ConnectorState>({
event,
Expand Down Expand Up @@ -877,6 +879,12 @@ export class WorkerAdapter<ConnectorState> {

// Loop through the batches of attachments
for (let i = lastProcessedBatchIndex; i < reducedAttachments.length; i++) {

// Check if we hit timeout
if (adapter.isTimeout) {
await sleep(DEFAULT_SLEEP_DELAY_MS);
}

const attachmentsBatch = reducedAttachments[i];

// Create a list of promises for parallel processing
Expand Down