Loading is the process of exporting data from DevRev back to the external system. This process includes creating new items in the external system and updating them with any changes made in DevRev.

The snap-in manages two phases for loading:

  • Load data
  • Load attachments

Each phase is defined in a separate file and is responsible for loading the corresponding data.

1import { AirdropEvent, EventType, spawn } from '@devrev/ts-adaas';
2
3export interface LoaderState {}
4
5export const initialLoaderState: LoaderState = {};
6
7function getWorkerPerLoadingPhase(event: AirdropEvent) {
8 let path;
9 switch (event.payload.event_type) {
10 case EventType.StartLoadingData:
11 case EventType.ContinueLoadingData:
12 path = __dirname + '/workers/load-data';
13 break;
14 case EventType.StartLoadingAttachments:
15 case EventType.ContinueLoadingAttachments:
16 path = __dirname + '/workers/load-attachments';
17 break;
18 }
19 return path;
20}
21
22const run = async (events: AirdropEvent[]) => {
23 for (const event of events) {
24 const file = getWorkerPerLoadingPhase(event);
25 await spawn<LoaderState>({
26 event,
27 initialState: initialLoaderState,
28 workerPath: file,
29 // options: {},
30 });
31 }
32};
33
34export default run;

State handling

Loading phases run as separate runtime instances, similar to extraction phases, with a maximum execution time of 12 minutes. These phases share a state, defined in the LoaderState interface. It is important to note that the loader state is separate from the extractor state. Access to the state is available through the SDK’s adapter object.

Built with