You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Required. An object of type __AirdropEvent__ that is received from the Airdrop platform.
43
-
44
-
*_initialState_
45
-
46
-
Required. Object of __any__ type that represents the initial state of the snap-in.
47
-
48
-
*_workerPath_
49
-
50
-
Required. A __string__ that represents the path to the worker file.
51
-
52
-
*_options_
53
-
54
-
Optional. An object of type **WorkerAdapterOptions**, which will be passed to the newly created worker. This worker will then initialize a `WorkerAdapter` by invoking the `processTask` function. The options include:
55
-
56
-
*`isLocalDevelopment`
57
-
58
-
A __boolean__ flag. If set to `true`, intermediary files containing extracted data will be stored on the local machine, which is useful during development. The default value is `false`.
59
-
60
-
*`timeout`
61
-
62
-
A __number__ that specifies the timeout duration for the lambda function, in milliseconds. The default is 10 minutes (10 * 60 * 1000 milliseconds), with a maximum allowable duration of 13 minutes (13 * 60 * 1000 milliseconds).
63
-
64
-
*`batchSize`
65
-
66
-
A __number__ that determines the maximum number of items to be processed and saved to an intermediary file before being sent to the Airdrop platform. The default batch size is 2,000.
67
-
68
-
#### Return value
69
-
70
-
A __promise__ that resolves once the worker has completed processing.
71
-
72
-
#### Example
73
-
74
-
```typescript
75
-
const run =async (events:AirdropEvent[]) => {
76
-
for (const event ofevents) {
77
-
const file =getWorkerPerExtractionPhase(event);
78
-
awaitspawn<ExtractorState>({
79
-
event,
80
-
initialState,
81
-
workerPath: file,
82
-
});
83
-
}
84
-
};
85
-
```
86
-
87
-
### `processTask` function
88
-
89
-
The `processTask` function retrieves the current state from the Airdrop platform and initializes a new `WorkerAdapter`.
90
-
It executes the code specified in the `task` parameter, which contains the worker's functionality.
91
-
If a timeout occurs, the function handles it by executing the `onTimeout` callback, ensuring the worker exits gracefully.
92
-
Both functions receive an `adapter` parameter, representing the initialized `WorkerAdapter` object.
93
-
94
-
95
-
#### Usage
96
-
```typescript
97
-
processTask({ task, onTimeout })
98
-
```
99
-
100
-
#### Parameters
101
-
102
-
*_task_
103
-
104
-
Required. A __function__ that defines the logic associated with the given event type.
105
-
106
-
*_onTimeout_
107
-
108
-
Required. A __function__ managing the timeout of the lambda invocation, including saving any necessary progress at the time of timeout.
message: 'Failed to extract external sync units. Lambda timeout.',
130
-
},
131
-
});
132
-
},
133
-
});
134
-
````
135
-
136
-
### `WorkerAdapter` class
137
-
138
-
Used to interact with Airdrop platform.
139
-
Provides utilities to emit events to the Airdrop platform, update the state of the snap-in and upload artifacts (files with data) to the platform.
140
-
141
-
### Usage
142
-
143
-
```typescript
144
-
newWorkerAdapter({
145
-
event,
146
-
adapterState,
147
-
options,
148
-
});
149
-
```
150
-
151
-
#### Parameters
152
-
153
-
*_event_
154
-
155
-
Required. An object of type __AirdropEvent__ that is received from the Airdrop platform.
156
-
157
-
*_adapterState_
158
-
159
-
Required. An object of type __State__, which represents the initial state of the adapter.
160
-
161
-
*_options_
162
-
163
-
Optional. An object of type __WorkerAdapterOptions__ that specifies additional configuration options for the `WorkerAdapter`. This object is passed via the `spawn` function.
164
-
165
-
#### Example
166
-
167
-
```typescript
168
-
const adapter =newWorkerAdapter<ConnectorState>({
169
-
event,
170
-
adapterState,
171
-
options,
172
-
});
173
-
```
174
-
175
-
### `WorkerAdapter.state` property
176
-
177
-
Getter and setter methods for working with the adapter state.
178
-
179
-
### Usage
180
-
181
-
```typescript
182
-
// get state
183
-
const adapterState =adapter.state;
184
-
185
-
// set state
186
-
adapter.state=newAdapterState;
187
-
```
188
-
189
-
#### Example
190
-
191
-
```typescript
192
-
exportconst initialState:ExtractorState= {
193
-
users: { completed: false },
194
-
tasks: { completed: false },
195
-
attachments: { completed: false },
196
-
};
197
-
198
-
adapter.state=initialState;
199
-
```
200
-
201
-
### `WorkerAdapter.initializeRepos` method
202
-
203
-
Initializes a `Repo` object for each item provided.
204
-
205
-
### Usage
206
-
207
-
```typescript
208
-
adapter.initializeRepos(repos);
209
-
```
210
-
211
-
#### Parameters
212
-
213
-
*_repos_
214
-
215
-
Required. An array of objects of type `RepoInterface`.
216
-
217
-
#### Example
218
-
219
-
This should typically be called within the function passed as a parameter to the `processTask` function in the data extraction phase.
220
-
221
-
```typescript
222
-
const repos = [
223
-
{
224
-
itemType: 'tasks',
225
-
normalize: normalizeTask,
226
-
}
227
-
];
228
-
229
-
adapter.initializeRepos(repos);
230
-
```
231
-
232
-
### `WorkerAdapter.getRepo` method
233
-
234
-
Finds a Repo from the initialized repos.
235
-
236
-
### Usage
237
-
238
-
```typescript
239
-
adapter.getRepo(itemType);
240
-
```
241
-
242
-
#### Parameters
243
-
244
-
*_itemType_
245
-
246
-
Required. A __string__ that represents the itemType property for the searched repo.
247
-
248
-
#### Return value
249
-
250
-
An object of type __Repo__ if the repo is found, otherwise __undefined__.
251
-
252
-
#### Example
253
-
254
-
This should typically be called within the function passed as a parameter to the `processTask` function.
255
-
256
-
```typescript
257
-
// Push users to the repository designated for 'users' data.
258
-
awaitadapter.getRepo('users')?.push(users);
259
-
```
260
-
261
-
### `WorkerAdapter.emit` method
262
-
263
-
Emits an event to the Airdrop platform.
264
-
265
-
### Usage
266
-
267
-
```typescript
268
-
adapter.emit( newEventType, data ):
269
-
```
270
-
271
-
#### Parameters
272
-
273
-
*_newEventType_
274
-
275
-
Required. The event type to be emitted, of type __ExtractorEventType__ or __LoaderEventType__.
276
-
277
-
*_data_
278
-
279
-
Optional. An object of type __EventData__ which represents the data to be sent with the event.
280
-
281
-
#### Return value
282
-
283
-
A __promise__, which resolves to undefined after the emit function completes its execution or rejects with an error.
284
-
285
-
#### Example
286
-
287
-
This should typically be called within the function passed as a parameter to the `processTask` function.
288
-
289
-
```typescript
290
-
// Emitting successfully finished data extraction.
0 commit comments