-
Notifications
You must be signed in to change notification settings - Fork 617
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merge: pull changes from
dev
(#4384)
Co-authored-by: Leonardo Giacone <[email protected]> Co-authored-by: Adrian Smijulj <[email protected]> Co-authored-by: adrians5j <[email protected]>
- Loading branch information
1 parent
c409f7c
commit 3996f51
Showing
96 changed files
with
2,137 additions
and
975 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
packages/api-dynamodb-to-elasticsearch/src/SynchronizationBuilder.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { | ||
Context, | ||
IDeleteOperationParams, | ||
IInsertOperationParams, | ||
IModifyOperationParams, | ||
IOperations | ||
} from "~/types"; | ||
import { Operations } from "~/Operations"; | ||
import { executeWithRetry, IExecuteWithRetryParams } from "~/executeWithRetry"; | ||
import { ITimer } from "@webiny/handler-aws"; | ||
|
||
export type ISynchronizationBuilderExecuteWithRetryParams = Omit< | ||
IExecuteWithRetryParams, | ||
"context" | "timer" | "maxRunningTime" | "operations" | ||
>; | ||
|
||
export interface ISynchronizationBuilder { | ||
insert(params: IInsertOperationParams): void; | ||
delete(params: IDeleteOperationParams): void; | ||
build: () => (params?: ISynchronizationBuilderExecuteWithRetryParams) => Promise<void>; | ||
} | ||
|
||
export interface ISynchronizationBuilderParams { | ||
timer: ITimer; | ||
context: Pick<Context, "elasticsearch" | "logger">; | ||
} | ||
|
||
export class SynchronizationBuilder implements ISynchronizationBuilder { | ||
private readonly timer: ITimer; | ||
private readonly context: Pick<Context, "elasticsearch" | "logger">; | ||
private readonly operations: IOperations; | ||
|
||
public constructor(params: ISynchronizationBuilderParams) { | ||
this.timer = params.timer; | ||
this.context = params.context; | ||
this.operations = new Operations(); | ||
} | ||
|
||
public insert(params: IInsertOperationParams): void { | ||
return this.operations.insert(params); | ||
} | ||
|
||
public modify(params: IModifyOperationParams): void { | ||
return this.operations.modify(params); | ||
} | ||
|
||
public delete(params: IDeleteOperationParams): void { | ||
return this.operations.delete(params); | ||
} | ||
|
||
public build() { | ||
return async (params?: ISynchronizationBuilderExecuteWithRetryParams) => { | ||
if (this.operations.total === 0) { | ||
return; | ||
} | ||
await executeWithRetry({ | ||
...params, | ||
maxRunningTime: this.timer.getRemainingMilliseconds(), | ||
timer: this.timer, | ||
context: this.context, | ||
operations: this.operations | ||
}); | ||
this.operations.clear(); | ||
}; | ||
} | ||
} | ||
|
||
export const createSynchronizationBuilder = ( | ||
params: ISynchronizationBuilderParams | ||
): ISynchronizationBuilder => { | ||
return new SynchronizationBuilder(params); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.