Skip to content

Commit f3df37f

Browse files
Simplify template writing (#30)
Review #28 and #29 first. ## Summary While reviewing Wrike and Aha! specification, I noticed that there's a couple commonalities that can be abstracted into template. Most notably: - Sentence to "not stringify error message" is put in shared - Template `data_fetching_return_expectations.plain` - Acceptance test template for testing external sync units - Template for "The {{ provider_name }} Internal client" - [#ISS-217157](https://app.devrev.ai/devrev/works/ISS-217157) --------- Co-authored-by: gasperzgonec <[email protected]>
1 parent 7fa7e98 commit f3df37f

11 files changed

+25
-22
lines changed

base_folder/src/functions/extraction/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ export interface ExtractorState {}
66

77
export const initialState: ExtractorState = {};
88

9-
109
function getWorkerPerExtractionPhase(event: FunctionInput) {
1110
let path;
1211
switch (event.payload.event_type) {

devrev-snapin-template.plain

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@
9494

9595
- The Function being implemented *MUST not* be called "extraction" or "loading".
9696

97+
- {% include "templates/should_not_modify_extraction_function.plain" %}
98+
9799
***Functional Requirements:***
98100

99101
- Implement The Function that only checks if The Function can be invoked.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
Here are the rules when `EXTRACTION_DATA_START` or `EXTRACTION_DATA_CONTINUE` event is received by the snap-in:
66

77
- 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.
89
- 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).
910
- 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).
1011
- 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.

docs/data-extraction.md

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,7 @@ This state object is shared across all invocations and keeps track of where the
1515

1616
## Triggering event
1717

18-
Airdrop initiates data extraction by starting the snap-in with a message with event type
19-
`EXTRACTION_DATA_START` when transitioning to the data extraction phase.
20-
21-
During the data extraction phase, the snap-in extracts data from an external system,
22-
prepares batches of data and uploads them in the form of artifacts (files) to DevRev.
23-
24-
The snap-in must respond to Airdrop with a message with event type of `EXTRACTION_DATA_PROGRESS`,
25-
together with an optional progress estimate when the maximum Airdrop snap-in runtime (13 minutes) has been reached.
26-
27-
If the extraction has been rate-limited by the external system and back-off is required, the snap-in
28-
must respond to Airdrop with a message with event type `EXTRACTION_DATA_DELAY` and specifying
29-
back-off time with `delay` attribute (in seconds as an integer).
30-
31-
In both cases, Airdrop starts the snap-in with a message with event type `EXTRACTION_DATA_CONTINUE`.
32-
In case of `EXTRACTION_DATA_PROGRESS` the restarting is immediate,
33-
meanwhile in case of `EXTRACTION_DATA_DELAY` the restarting is delayed for the given number of seconds.
34-
35-
Once the data extraction is done, the snap-in must respond to Airdrop with a message with event type `EXTRACTION_DATA_DONE`.
36-
37-
If data extraction failed in any moment of extraction, the snap-in must respond to Airdrop with a
38-
message with event type `EXTRACTION_DATA_ERROR`.
18+
Refer to the resource [data-extraction-rules-for-emitting-events.md](docs/data-extraction-rules-for-emitting-events.md) for the rules for emitting events for The Extraction Function.
3919

4020
## Implementation
4121

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
The Functions implemented *should* also return:
2+
- `status_code` - a status code from The API.
3+
- `api_delay` - Delay in seconds to wait before retrying the request to The API (if no rate limit, set to 0)
4+
- `message` - Information about the call the The Function.
5+
- Note: Every The Function should handle rate limiting.

templates/external_domain_metadata_boilerplate.plain

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
- The External Domain Metadata JSON object *MUST* be imported without "as" statement in The Implementation Code.
1313

14+
- {% include "templates/should_not_modify_extraction_function.plain" %}
15+
1416
***Test Requirements:***
1517

1618
- Validate generated The External Domain Metadata JSON object with the chef-cli tool (The Chef CLI) using the command "chef-cli validate-metadata":
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Test The Extraction Function using the resource [{{ resource_name }}](test_data/{{ resource_name }}).
2+
- Expect The Callback Server to receive *a single* event with "event_type" "EXTRACTION_EXTERNAL_SYNC_UNITS_DONE".
3+
- Let `external_sync_units_array = <event_from_callback_server>["event_data"]["external_sync_units"]` (array of objects).
4+
- Expect `external_sync_units_array` to exist and be an array.
5+
- Expect `len(external_sync_units_array) = {{ expected_external_sync_unit_count }}`.
6+
- Out of `external_sync_units_array`, expect that there exists and element that has "name" equal to "{{ expected_external_sync_unit_name }}".

templates/initial_domain_mapping_boilerplate.plain

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
- The External Domain Metadata JSON object should not be modified. If there are discrepancies between The External Domain Metadata JSON object and The Initial Domain Mapping JSON object, assume The External Domain Metadata JSON object is correct and The Initial Domain Mapping JSON object needs to be adjusted.
2929

30+
- {% include "templates/should_not_modify_extraction_function.plain" %}
31+
3032
***Test Requirements:***
3133

3234
- Validate generated The Initial Domain Mapping JSON object with the chef-cli tool (The Chef CLI) using the command "chef-cli initial-mapping check -m <The External Domain Metadata JSON object file>":

templates/internal_client.plain

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The {{ external_system_name }} Internal Client is a TypeScript service that communicates with The API. These are the rules for The {{ external_system_name }} Internal Client:
2+
- If we need to create a new request to The API, we must create a new method in The {{ external_system_name }} Internal Client.
3+
- Communication with The API must be completely abstracted away from The Function. The Function must be able to initialize The {{ external_system_name }} Internal Client, call the relevant method from The {{ external_system_name }} Internal Client and get the response from The API.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The Extraction Function *must not* be modified.

0 commit comments

Comments
 (0)