|
1 |
| -# Loading |
| 1 | +Loading is the process of exporting data from DevRev back to the external system. |
| 2 | +This process includes creating new items in the external system and updating them with any changes made in DevRev. |
2 | 3 |
|
3 |
| -To be added. |
| 4 | +The snap-in manages two phases for loading: |
| 5 | +* Load data |
| 6 | +* Load attachments |
| 7 | + |
| 8 | +Each phase is defined in a separate file and is responsible for loading the corresponding data. |
| 9 | + |
| 10 | +```typescript |
| 11 | +import { AirdropEvent, EventType, spawn } from '@devrev/ts-adaas'; |
| 12 | + |
| 13 | +export interface LoaderState {} |
| 14 | + |
| 15 | +export const initialLoaderState: LoaderState = {}; |
| 16 | + |
| 17 | +function getWorkerPerLoadingPhase(event: AirdropEvent) { |
| 18 | + let path; |
| 19 | + switch (event.payload.event_type) { |
| 20 | + case EventType.StartLoadingData: |
| 21 | + case EventType.ContinueLoadingData: |
| 22 | + path = __dirname + '/workers/load-data'; |
| 23 | + break; |
| 24 | + case EventType.StartLoadingAttachments: |
| 25 | + case EventType.ContinueLoadingAttachments: |
| 26 | + path = __dirname + '/workers/load-attachments'; |
| 27 | + break; |
| 28 | + } |
| 29 | + return path; |
| 30 | +} |
| 31 | + |
| 32 | +const run = async (events: AirdropEvent[]) => { |
| 33 | + for (const event of events) { |
| 34 | + const file = getWorkerPerLoadingPhase(event); |
| 35 | + await spawn<LoaderState>({ |
| 36 | + event, |
| 37 | + initialState: initialLoaderState, |
| 38 | + workerPath: file, |
| 39 | + // options: {}, |
| 40 | + }); |
| 41 | + } |
| 42 | +}; |
| 43 | + |
| 44 | +export default run; |
| 45 | +``` |
| 46 | + |
| 47 | +## State handling |
| 48 | + |
| 49 | +Loading phases run as separate runtime instances, similar to extraction phases, with a maximum execution time of 12 minutes. |
| 50 | +These phases share a `state`, defined in the `LoaderState` interface. |
| 51 | +It is important to note that the loader state is separate from the extractor state. |
| 52 | +Access to the `state` is available through the SDK's `adapter` object. |
0 commit comments