Skip to content

Commit 7fa7e98

Browse files
Extraction function scaffolding in base folder (#29)
Review #28 before this one. ## Summary One of last week's action point was to ensure worker file split that is native for DevRev's snap-in development. Example from Asana https://github.com/devrev/airdrop-asana-snap-in/blob/7f2e49e906a9b3e3c7d13b3391fdb588dec2ad7b/code/src/functions/extraction/index.ts#L36-L55 Note that this is just suggestion (not a snap-in expert 😁). Curious to hear your suggestions. - [#ISS-217157](https://app.devrev.ai/devrev/works/ISS-217157) --------- Co-authored-by: gasperzgonec <[email protected]>
1 parent dc81fcd commit 7fa7e98

File tree

6 files changed

+87
-0
lines changed

6 files changed

+87
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
import extraction from './functions/extraction';
2+
13
export const functionFactory = {
24
// Add your functions here
5+
extraction,
36
} as const;
47

58
export type FunctionFactoryType = keyof typeof functionFactory;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { convertToAirdropEvent } from '../../core/utils';
2+
import { FunctionInput } from '../../core/types';
3+
import { spawn, EventType } from '@devrev/ts-adaas';
4+
5+
export interface ExtractorState {}
6+
7+
export const initialState: ExtractorState = {};
8+
9+
10+
function getWorkerPerExtractionPhase(event: FunctionInput) {
11+
let path;
12+
switch (event.payload.event_type) {
13+
case EventType.ExtractionExternalSyncUnitsStart:
14+
path = __dirname + '/workers/external-sync-units-extraction';
15+
break;
16+
case EventType.ExtractionMetadataStart:
17+
path = __dirname + '/workers/metadata-extraction';
18+
break;
19+
case EventType.ExtractionDataStart:
20+
case EventType.ExtractionDataContinue:
21+
path = __dirname + '/workers/data-extraction';
22+
break;
23+
case EventType.ExtractionAttachmentsStart:
24+
case EventType.ExtractionAttachmentsContinue:
25+
path = __dirname + '/workers/attachments-extraction';
26+
break;
27+
}
28+
return path;
29+
}
30+
31+
const run = async (events: FunctionInput[]) => {
32+
for (const event of events) {
33+
const file = getWorkerPerExtractionPhase(event);
34+
await spawn({
35+
event: convertToAirdropEvent(event),
36+
workerPath: file,
37+
initialState: initialState,
38+
});
39+
}
40+
};
41+
42+
export default run;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { ExtractorEventType, processTask } from '@devrev/ts-adaas';
2+
import { ExtractorState } from "../index";
3+
4+
processTask<ExtractorState>({
5+
task: async ({ adapter }) => {},
6+
onTimeout: async ({ adapter }) => {
7+
await adapter.emit(ExtractorEventType.ExtractionAttachmentsProgress);
8+
},
9+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { ExtractorEventType, processTask } from "@devrev/ts-adaas";
2+
import { ExtractorState } from "../index";
3+
4+
processTask<ExtractorState>({
5+
task: async ({ adapter }) => {},
6+
onTimeout: async ({ adapter }) => {
7+
await adapter.emit(ExtractorEventType.ExtractionDataProgress);
8+
},
9+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { ExtractorEventType, processTask } from "@devrev/ts-adaas";
2+
import { ExtractorState } from "../index";
3+
4+
processTask<ExtractorState>({
5+
task: async ({ adapter }) => {},
6+
onTimeout: async ({ adapter }) => {
7+
await adapter.emit(ExtractorEventType.ExtractionExternalSyncUnitsError, {
8+
error: {
9+
message: 'Failed to extract external sync units. Lambda timeout.',
10+
},
11+
});
12+
},
13+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { processTask, ExtractorEventType } from '@devrev/ts-adaas';
2+
import { ExtractorState } from '../index';
3+
4+
processTask<ExtractorState>({
5+
task: async ({ adapter }) => {},
6+
onTimeout: async ({ adapter }) => {
7+
await adapter.emit(ExtractorEventType.ExtractionMetadataError, {
8+
error: { message: 'Failed to extract metadata. Lambda timeout.' },
9+
});
10+
},
11+
});

0 commit comments

Comments
 (0)