Skip to content
This repository has been archived by the owner on Feb 27, 2024. It is now read-only.

Commit

Permalink
feat: adds ability to customize retry strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
Enngage committed Sep 14, 2022
1 parent b60e29e commit 4c3a2a8
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 12 deletions.
2 changes: 2 additions & 0 deletions lib/clean/clean.models.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { IProcessedItem } from '../core';
import { IRetryStrategyOptions } from '@kontent-ai/core-sdk';

export interface ICleanConfig {
projectId: string;
apiKey: string;
baseUrl?: string;
onDelete?: (item: IProcessedItem) => void;
retryStrategy?: IRetryStrategyOptions;
}

export interface ICleanResult {
Expand Down
5 changes: 3 additions & 2 deletions lib/clean/clean.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AssetFolderModels, ManagementClient } from '@kontent-ai/management-sdk';
import { HttpService } from '@kontent-ai/core-sdk';

import { defaultWorkflowCodename, handleError, ItemType } from '../core';
import { defaultRetryStrategy, defaultWorkflowCodename, handleError, ItemType } from '../core';
import { ICleanConfig, ICleanResult } from './clean.models';

export class CleanService {
Expand All @@ -14,7 +14,8 @@ export class CleanService {
baseUrl: config.baseUrl,
httpService: new HttpService({
logErrorsToConsole: false
})
}),
retryStrategy: config.retryStrategy ?? defaultRetryStrategy
});
}

Expand Down
8 changes: 8 additions & 0 deletions lib/core/global-helper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { SharedModels } from '@kontent-ai/management-sdk';
import { IRetryStrategyOptions } from '@kontent-ai/core-sdk';

export const defaultRetryStrategy: IRetryStrategyOptions = {
addJitter: true,
canRetryError: (err) => true, // so that timeout errors are retried
maxAttempts: 3,
deltaBackoffMs: 1000
};

export function getFilenameWithoutExtension(filename: string): string {
if (!filename) {
Expand Down
4 changes: 3 additions & 1 deletion lib/export/export.models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import {
ProjectContracts,
WorkflowContracts,
WebhookContracts,
CollectionContracts,
CollectionContracts
} from '@kontent-ai/management-sdk';
import { IRetryStrategyOptions } from '@kontent-ai/core-sdk';

import { IProcessedItem, IPackageMetadata, ItemType } from '../core';

Expand All @@ -22,6 +23,7 @@ export interface IExportConfig {
onExport?: (item: IProcessedItem) => void;
exportFilter?: ItemType[];
skipValidation: boolean;
retryStrategy?: IRetryStrategyOptions;
}

export interface IExportData {
Expand Down
3 changes: 2 additions & 1 deletion lib/export/export.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
import {HttpService } from '@kontent-ai/core-sdk';

import { IExportAllResult, IExportConfig, IExportData } from './export.models';
import { ItemType } from '../core';
import { defaultRetryStrategy, ItemType } from '../core';
import { version } from '../../package.json';

export class ExportService {
Expand All @@ -30,6 +30,7 @@ export class ExportService {
httpService: new HttpService({
logErrorsToConsole: false
}),
retryStrategy: config.retryStrategy ?? defaultRetryStrategy
});
}

Expand Down
4 changes: 3 additions & 1 deletion lib/import/import.models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import {
LanguageVariantContracts,
TaxonomyContracts,
ProjectContracts,
WorkflowContracts,
WorkflowContracts
} from '@kontent-ai/management-sdk';
import { IRetryStrategyOptions } from '@kontent-ai/core-sdk';

import { IProcessedItem, ItemType, IPackageMetadata } from '../core';

export interface IImportConfig {
retryStrategy?: IRetryStrategyOptions;
workflowIdForImportedItems?: string;
baseUrl?: string;
projectId: string;
Expand Down
10 changes: 3 additions & 7 deletions lib/import/import.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ import {
ValidImportModel,
handleError,
defaultWorkflowCodename,
defaultObjectId
defaultObjectId,
defaultRetryStrategy
} from '../core';
import { IBinaryFile, IImportConfig, IImportSource } from './import.models';
import { HttpService } from '@kontent-ai/core-sdk';
Expand All @@ -53,12 +54,7 @@ export class ImportService {
httpService: new HttpService({
logErrorsToConsole: false
}),
retryStrategy: {
addJitter: true,
canRetryError: (err) => true, // so that timeout errors are retried
maxAttempts: 3,
deltaBackoffMs: 1000
}
retryStrategy: config.retryStrategy ?? defaultRetryStrategy
});
}

Expand Down

0 comments on commit 4c3a2a8

Please sign in to comment.