Skip to content

Commit a553646

Browse files
committed
Update docs
1 parent 3f2f0c6 commit a553646

File tree

5 files changed

+61
-8
lines changed

5 files changed

+61
-8
lines changed
File renamed without changes.
File renamed without changes.

docs/data-extraction-rules-for-emitting-events.md

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,63 @@
44

55
Here are the rules when `EXTRACTION_DATA_START` or `EXTRACTION_DATA_CONTINUE` event is received by the snap-in:
66

7-
- If there's a timeout ("onTimeout" method in "spawn" method), the snap-in should emit an event with type `EXTRACTION_DATA_PROGRESS` (no "data" payload).
8-
- Note: Event `EXTRACTION_DATA_PROGRESS` **MUST NEVER** be emitted if the "task" method in The Worker Thread. The Only place where `EXTRACTION_DATA_PROGRESS` can be emitted is in the "onTimeout" method in The Worker Thread.
7+
- The `EXTRACTION_DATA_PROGRESS` event *MUST* only be emitted from within the "onTimeout" handler of "processTask" method.
8+
- The `EXTRACTION_DATA_PROGRESS` event *MUST NEVER* be emitted from within the "task" handler of "processTask" method.
99
- If the extraction is successful and all the resources have been extracted, the snap-in should emit an event with type `EXTRACTION_DATA_DONE` (no "data" payload).
1010
- In case of unexpected error, the snap-in should emit an event with type `EXTRACTION_DATA_ERROR` ("data" payload should contain attribute "error" - error message as a string).
11-
- In case of rate limiting (status code 429) for "data extraction", the snap-in *must* emit an event with type `EXTRACTION_DATA_DELAY`. If emitting event of type `EXTRACTION_DATA_DELAY`, you *must* also provide a "delay" attribute, specifying the delay in seconds as an integer.
11+
- In case of rate limiting (status code 429) for "data extraction", the snap-in _must_ emit an event with type `EXTRACTION_DATA_DELAY`. If emitting event of type `EXTRACTION_DATA_DELAY`, you _must_ also provide a "delay" attribute, specifying the delay in seconds as an integer.
1212
- Example: `await adapter.emit(ExtractorEventType.ExtractionDataDelay, { delay: "30" });`
13+
- If rate limiting is encountered at ANY point during data extraction (including nexted API calls) the snap-in _must_ emit an event with type `EXTRACTION_DATA_DELAY`.
14+
- The delay attribute should be extracted from the API response.
15+
- Rate limiting should be checked immediately after each API call, before proceeding with further processing.
16+
- If rate limiting is encountered at ANY point during data extraction (including nested API calls within Promise.all, async operations, or iterations over an array) the snap-in _must_ emit an event with type `EXTRACTION_DATA_DELAY` and IMMEDIATELY RETURN from the task function.
17+
- Rate limiting MUST be checked immediately after EACH AND EVERY API call, before proceeding with any further processing.
18+
- For asynchronous operations (e.g., Promise.all), rate limiting must be checked within each async function and propagated appropriately.
19+
- Example pattern for checking rate limiting:
20+
- In case we're making a single API call:
21+
```typescript
22+
const response = await trelloClient.someMethod();
23+
if (response.status_code === 429) {
24+
await adapter.emit(ExtractorEventType.ExtractionDataDelay, {
25+
delay: response.api_delay,
26+
});
27+
return; // Must return immediately
28+
}
29+
```
30+
31+
- In case we're iterating over an array and making API calls within the iteration:
32+
```typescript
33+
let rateLimited = false;
34+
let delay = 0;
35+
36+
const results = await Promise.all(
37+
items.map(async (item) => {
38+
// Skip if already rate limited
39+
if (rateLimited) return null;
40+
41+
// Make API request
42+
const response = await apiClient.someMethod();
43+
44+
// Handle rate limiting (HTTP 429)
45+
if (response.status_code === 429) {
46+
rateLimited = true;
47+
delay = response.api_delay; // calculate delay from response
48+
return null;
49+
}
50+
51+
return response.data // or similar
52+
})
53+
);
54+
55+
if (rateLimited) {
56+
await adapter.emit(ExtractorEventType.ExtractionDataDelay, {
57+
delay: delay,
58+
});
59+
return;
60+
}
61+
```
62+
NOTE: You **MUST NOT** throw an error inside the `Promise.all` block (this would kill the data extraction process).
63+
1364

1465
## Input event: `EXTRACTION_EXTERNAL_SYNC_UNITS_START`
1566

@@ -22,19 +73,21 @@ Here are the rules when `EXTRACTION_EXTERNAL_SYNC_UNITS_START` event is received
2273
## Input event: `EXTRACTION_METADATA_START`
2374

2475
Here are the rules when `EXTRACTION_METADATA_START` event is received by the snap-in:
76+
2577
- If "metadata extraction" is successful and the snap-in has extracted all the metadata, the snap-in should emit an event with type `EXTRACTION_METADATA_DONE` (no "data" payload).
2678
- In case of unexpected error, the snap-in should emit an event with type `EXTRACTION_METADATA_ERROR` ("data" payload should contain attribute "error" - error message as a string).
2779

2880
## Input event: `EXTRACTION_ATTACHMENTS_START` or `EXTRACTION_ATTACHMENTS_CONTINUE`
2981

3082
Here are the rules when `EXTRACTION_ATTACHMENTS_START` or `EXTRACTION_ATTACHMENTS_CONTINUE` event is received by the snap-in:
83+
3184
- If "attachments extraction" is successful and the snap-in has extracted all the attachments, the snap-in should emit an event with type "EXTRACTION_ATTACHMENTS_DONE"
3285
- If case of unexpected error, the snap-in should emit an event with type "EXTRACTION_ATTACHMENTS_ERROR" ("data" payload should contain attribute "error" - error message as a string).
3386
- In case of rate limiting (status code 429) for "attachments extraction", the snap-in should also emit an event with type "EXTRACTION_ATTACHMENTS_DELAY". If emitting event of type "EXTRACTION_ATTACHMENTS_DELAY", you *must* also provide a "delay" attribute, specifying the delay in seconds as an integer.
3487
- Example: `await adapter.emit(ExtractorEventType.ExtractionAttachmentsDelay, { delay: "30" });`
3588
- If there's a timeout ("onTimeout" method in "spawn" method), the snap-in should emit an event with type "EXTRACTION_ATTACHMENTS_PROGRESS".
3689

37-
3890
## IMPORTANT FOR ALL INPUT EVENTS
3991

40-
- In all cases, only a single event should be emitted.
92+
- In all cases, only a single event should be emitted.
93+

docs/external-sync-units-extraction.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const externalSyncUnits: ExternalSyncUnit[] = [
3838
- `item_count`: The number of items (issues, tickets, comments or others) in the external system.
3939
Item count should be provided if it can be obtained in a lightweight manner, such as by calling an API endpoint.
4040
If there is no such way to get it (for example, if the items would need to be extracted to count them),
41-
then the item count should be `-1` to avoid blocking the import with long-running queries.
41+
then the item count should be set to `undefined`.
4242

4343
The snap-in must respond to Airdrop with a message, which contains a list of external sync units as a payload:
4444

docs/incremental_mode.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ processTask<ExtractorState>({
7676

7777
// If this is an incremental sync, we need to reset the state for the item types.
7878
if (adapter.event.payload.event_context.mode === SyncMode.INCREMENTAL) {
79-
adapter.state.tasks = initialState.tasks;
80-
adapter.state.attachments = initialState.attachments;
79+
adapter.state.tasks = initialState.tasks; // Or something along the lines of adapter.state.tasks.completed = false;
80+
adapter.state.attachments = initialState.attachments; // Or something along the lines of adapter.state.attachments.completed = false;
8181
adapter.state.tasks.modifiedSince = adapter.state.lastSuccessfulSyncStarted;
8282
}
8383
}

0 commit comments

Comments
 (0)