Skip to content

Commit 6fc6691

Browse files
committed
Started using 'getEventType'.
1 parent ff1b5b9 commit 6fc6691

File tree

3 files changed

+10
-24
lines changed

3 files changed

+10
-24
lines changed

src/common/helpers.ts

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,42 +28,23 @@ const EVENT_TYPE_TRANSLATION_TABLE = {
2828
"EXTRACTION_ATTACHMENTS_CONTINUE": EventType.ExtractionAttachmentsContinue,
2929
"EXTRACTION_DATA_DELETE": EventType.ExtractionDataDelete,
3030
"EXTRACTION_ATTACHMENTS_DELETE": EventType.ExtractionAttachmentsDelete,
31-
32-
"EXTRACTION_EXTERNAL_SYNC_UNITS_DONE": ExtractorEventType.ExtractionExternalSyncUnitsDone,
33-
"EXTRACTION_EXTERNAL_SYNC_UNITS_ERROR": ExtractorEventType.ExtractionExternalSyncUnitsError,
34-
"EXTRACTION_METADATA_DONE": ExtractorEventType.ExtractionMetadataDone,
35-
"EXTRACTION_METADATA_ERROR": ExtractorEventType.ExtractionMetadataError,
36-
"EXTRACTION_DATA_PROGRESS": ExtractorEventType.ExtractionDataProgress,
37-
"EXTRACTION_DATA_DELAY": ExtractorEventType.ExtractionDataDelay,
38-
"EXTRACTION_DATA_DONE": ExtractorEventType.ExtractionDataDone,
39-
"EXTRACTION_DATA_ERROR": ExtractorEventType.ExtractionDataError,
40-
"EXTRACTION_ATTACHMENTS_PROGRESS": ExtractorEventType.ExtractionAttachmentsProgress,
41-
"EXTRACTION_ATTACHMENTS_DELAY": ExtractorEventType.ExtractionAttachmentsDelay,
42-
"EXTRACTION_ATTACHMENTS_DONE": ExtractorEventType.ExtractionAttachmentsDone,
43-
"EXTRACTION_ATTACHMENTS_ERROR": ExtractorEventType.ExtractionAttachmentsError,
44-
"EXTRACTION_DATA_DELETE_DONE": ExtractorEventType.ExtractionDataDeleteDone,
45-
"EXTRACTION_DATA_DELETE_ERROR": ExtractorEventType.ExtractionDataDeleteError,
46-
"EXTRACTION_ATTACHMENTS_DELETE_DONE": ExtractorEventType.ExtractionAttachmentsDeleteDone,
47-
"EXTRACTION_ATTACHMENTS_DELETE_ERROR": ExtractorEventType.ExtractionAttachmentsDeleteError
4831
};
4932

5033
/**
5134
* Translates Event type from the old naming scheme to the new one
5235
*/
53-
export function getEventType(eventType: string): EventType | ExtractorEventType {
36+
export function getEventType(eventType: string): EventType {
5437
// If we notice that the event has a newer translation, translate to that
5538
if(eventType in EVENT_TYPE_TRANSLATION_TABLE){
5639
return EVENT_TYPE_TRANSLATION_TABLE[eventType as keyof typeof EVENT_TYPE_TRANSLATION_TABLE];
5740
}
5841

59-
// Return the correct event type
60-
if (eventType in ExtractorEventType) {
61-
return eventType as ExtractorEventType;
62-
}else if (eventType in EventType) {
42+
// Event type doesn't need translation, return
43+
if (eventType in EventType) {
6344
return eventType as EventType;
6445
}
6546

66-
return ExtractorEventType.UnknownEventType;
47+
return EventType.UnknownEventType;
6748
}
6849

6950
export function getTimeoutErrorEventType(eventType: EventType): {

src/types/extraction.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ export enum EventType {
3131
ContinueLoadingAttachments = 'CONTINUE_LOADING_ATTACHMENTS',
3232
StartDeletingLoaderState = 'START_DELETING_LOADER_STATE',
3333
StartDeletingLoaderAttachmentState = 'START_DELETING_LOADER_ATTACHMENT_STATE',
34+
35+
// Unknown
36+
UnknownEventType = 'UNKNOWN_EVENT_TYPE',
3437
}
3538

3639
/**

src/workers/spawn.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
12
import yargs from 'yargs';
23
import { hideBin } from 'yargs/helpers';
34

45
import { emit } from '../common/control-protocol';
5-
import { getMemoryUsage, getTimeoutErrorEventType } from '../common/helpers';
6+
import { getMemoryUsage, getEventType, getTimeoutErrorEventType } from '../common/helpers';
67
import { Logger, serializeError } from '../logger/logger';
78
import {
89
AirdropEvent,
@@ -93,6 +94,7 @@ export async function spawn<ConnectorState>({
9394
initialDomainMapping,
9495
options,
9596
}: SpawnFactoryInterface<ConnectorState>): Promise<void> {
97+
event.payload.event_type = getEventType(event.payload.event_type);
9698
const logger = new Logger({ event, options });
9799
const script = getWorkerPath({
98100
event,

0 commit comments

Comments
 (0)