Skip to content

Commit 10bc037

Browse files
committed
Implemented a crude SQS size overflow workaround.
1 parent ff23597 commit 10bc037

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/workers/worker-adapter.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ import {
4848
import { Uploader } from '../uploader/uploader';
4949
import { Artifact, SsorAttachment } from '../uploader/uploader.interfaces';
5050

51+
const MAX_MESSAGE_LENGTH: number = 200_000;
52+
5153
export function createWorkerAdapter<ConnectorState>({
5254
event,
5355
adapterState,
@@ -91,6 +93,9 @@ export class WorkerAdapter<ConnectorState> {
9193
private _mappers: Mappers;
9294
private uploader: Uploader;
9395

96+
// Length of the resulting artifact JSON object string.
97+
private currentLength: number = 0;
98+
9499
constructor({
95100
event,
96101
adapterState,
@@ -149,12 +154,20 @@ export class WorkerAdapter<ConnectorState> {
149154
itemType: repo.itemType,
150155
...(shouldNormalize && { normalize: repo.normalize }),
151156
onUpload: (artifact: Artifact) => {
157+
let newLength = JSON.stringify(artifact).length;
158+
152159
// We need to store artifacts ids in state for later use when streaming attachments
153160
if (repo.itemType === AIRDROP_DEFAULT_ITEM_TYPES.ATTACHMENTS) {
154161
this.state.toDevRev?.attachmentsMetadata.artifactIds.push(
155162
artifact.id
156163
);
157164
}
165+
166+
if(this.currentLength + newLength > MAX_MESSAGE_LENGTH) {
167+
// TODO: We need to call the adapter's `onTimeout` here and `emit` the Progress event.
168+
// We might have to run the `uploadAllRepos` as well.
169+
this.handleTimeout();
170+
}
158171
},
159172
options: this.options,
160173
});

0 commit comments

Comments
 (0)