Skip to content

Commit

Permalink
merge: pull changes from dev (#4384)
Browse files Browse the repository at this point in the history
Co-authored-by: Leonardo Giacone <[email protected]>
Co-authored-by: Adrian Smijulj <[email protected]>
Co-authored-by: adrians5j <[email protected]>
  • Loading branch information
4 people authored Nov 14, 2024
1 parent c409f7c commit 3996f51
Show file tree
Hide file tree
Showing 96 changed files with 2,137 additions and 975 deletions.
43 changes: 32 additions & 11 deletions .github/workflows/pullRequests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ jobs:
run-cache-key: ${{ steps.run-cache-key.outputs.run-cache-key }}
is-fork-pr: ${{ steps.is-fork-pr.outputs.is-fork-pr }}
changed-packages: ${{ steps.detect-changed-packages.outputs.changed-packages }}
latest-webiny-version: ${{ steps.latest-webiny-version.outputs.latest-webiny-version }}
steps:
- uses: actions/setup-node@v4
with:
Expand Down Expand Up @@ -79,6 +80,25 @@ jobs:
.github/workflows/wac/utils/runNodeScripts/listChangedPackages.js '${{
steps.detect-changed-files.outputs.changed_files }}')" >>
$GITHUB_OUTPUT
- name: Get latest Webiny version on NPM
id: latest-webiny-version
run: >-
echo "latest-webiny-version=$(npm view @webiny/cli version)" >>
$GITHUB_OUTPUT
runs-on: ubuntu-latest
env:
NODE_OPTIONS: '--max_old_space_size=4096'
YARN_ENABLE_IMMUTABLE_INSTALLS: false
assignMilestone:
name: Assign milestone
needs: constants
steps:
- uses: actions/setup-node@v4
with:
node-version: 20
- uses: actions/checkout@v4
- name: Print latest Webiny version
run: echo ${{ needs.constants.outputs.latest-webiny-version }}
runs-on: ubuntu-latest
env:
NODE_OPTIONS: '--max_old_space_size=4096'
Expand Down Expand Up @@ -118,7 +138,6 @@ jobs:
staticCodeAnalysis:
needs:
- constants
- build
name: Static code analysis
steps:
- uses: actions/setup-node@v4
Expand Down Expand Up @@ -203,8 +222,8 @@ jobs:
- name: Packages to test with Jest
id: list-packages
run: >-
echo ${{
steps.list-packages-to-jest-test.outputs.packages-to-jest-test }}
echo '${{
steps.list-packages-to-jest-test.outputs.packages-to-jest-test }}'
env:
NODE_OPTIONS: '--max_old_space_size=4096'
YARN_ENABLE_IMMUTABLE_INSTALLS: false
Expand Down Expand Up @@ -322,8 +341,8 @@ jobs:
- name: Packages to test with Jest
id: list-packages
run: >-
echo ${{
steps.list-packages-to-jest-test.outputs.packages-to-jest-test }}
echo '${{
steps.list-packages-to-jest-test.outputs.packages-to-jest-test }}'
env:
NODE_OPTIONS: '--max_old_space_size=4096'
YARN_ENABLE_IMMUTABLE_INSTALLS: false
Expand Down Expand Up @@ -394,7 +413,8 @@ jobs:
'[[{"cmd":"packages/api-aco
--storage=ddb-es,ddb","storage":"ddb-es","packageName":"api-aco","id":"8f23ec33f547aa62236f5c71115688d6"},{"cmd":"packages/api-audit-logs
--storage=ddb-es,ddb","storage":"ddb-es","packageName":"api-audit-logs","id":"a292444cd9100f78d8fc196274393ea8"},{"cmd":"packages/api-dynamodb-to-elasticsearch
--storage=ddb-es,ddb","storage":["ddb-es"],"packageName":"api-dynamodb-to-elasticsearch","id":"e2c325f0940ba5fb5a891a8cf74fca61"},{"cmd":"packages/api-elasticsearch","storage":["ddb-es","ddb-os"],"packageName":"api-elasticsearch","id":"430874606aeb8e8041b325955f9330e3"},{"cmd":"packages/api-elasticsearch-tasks
--storage=ddb-es,ddb","storage":["ddb-es"],"packageName":"api-dynamodb-to-elasticsearch","id":"e2c325f0940ba5fb5a891a8cf74fca61"},{"cmd":"packages/api-elasticsearch
--storage=ddb-es,ddb","storage":["ddb-es"],"packageName":"api-elasticsearch","id":"5963079c60b96202bbaf2a802ad14383"},{"cmd":"packages/api-elasticsearch-tasks
--storage=ddb-es,ddb","storage":"ddb-es","packageName":"api-elasticsearch-tasks","id":"d81ad1d024a8746cc440e2e548770f8f"},{"cmd":"packages/api-file-manager
--storage=ddb-es,ddb","storage":"ddb-es","packageName":"api-file-manager","id":"d6f293add4a252b96cbd770ab6e80557"},{"cmd":"packages/api-form-builder
--storage=ddb-es,ddb","storage":"ddb-es","packageName":"api-form-builder","id":"3753bde0144d808eb15c755b7176386c"},{"cmd":"packages/api-form-builder-so-ddb-es
Expand Down Expand Up @@ -437,8 +457,8 @@ jobs:
- name: Packages to test with Jest
id: list-packages
run: >-
echo ${{
steps.list-packages-to-jest-test.outputs.packages-to-jest-test }}
echo '${{
steps.list-packages-to-jest-test.outputs.packages-to-jest-test }}'
env:
NODE_OPTIONS: '--max_old_space_size=4096'
YARN_ENABLE_IMMUTABLE_INSTALLS: false
Expand Down Expand Up @@ -522,7 +542,8 @@ jobs:
'[[{"cmd":"packages/api-aco
--storage=ddb-os,ddb","storage":"ddb-os","packageName":"api-aco","id":"e4b1b5ebc172f2657485e41c35ad1cd7"},{"cmd":"packages/api-audit-logs
--storage=ddb-os,ddb","storage":"ddb-os","packageName":"api-audit-logs","id":"b36aac5f0e34dc4583e5422ae589f1ed"},{"cmd":"packages/api-dynamodb-to-elasticsearch
--storage=ddb-os,ddb","storage":["ddb-os"],"packageName":"api-dynamodb-to-elasticsearch","id":"6e0b282c3d135703e52b2c55822d4fb0"},{"cmd":"packages/api-elasticsearch","storage":["ddb-es","ddb-os"],"packageName":"api-elasticsearch","id":"430874606aeb8e8041b325955f9330e3"},{"cmd":"packages/api-elasticsearch-tasks
--storage=ddb-os,ddb","storage":["ddb-os"],"packageName":"api-dynamodb-to-elasticsearch","id":"6e0b282c3d135703e52b2c55822d4fb0"},{"cmd":"packages/api-elasticsearch
--storage=ddb-os,ddb","storage":["ddb-os"],"packageName":"api-elasticsearch","id":"b0f477d6b209f654714809b318be888e"},{"cmd":"packages/api-elasticsearch-tasks
--storage=ddb-os,ddb","storage":"ddb-os","packageName":"api-elasticsearch-tasks","id":"580a9577fdbd4a241034a42e1a47dee5"},{"cmd":"packages/api-file-manager
--storage=ddb-os,ddb","storage":"ddb-os","packageName":"api-file-manager","id":"346430a79981d3e214c87254a08e31b2"},{"cmd":"packages/api-form-builder
--storage=ddb-os,ddb","storage":"ddb-os","packageName":"api-form-builder","id":"d386cddfd3c366ad9955193dcfe74363"},{"cmd":"packages/api-form-builder-so-ddb-es
Expand Down Expand Up @@ -565,8 +586,8 @@ jobs:
- name: Packages to test with Jest
id: list-packages
run: >-
echo ${{
steps.list-packages-to-jest-test.outputs.packages-to-jest-test }}
echo '${{
steps.list-packages-to-jest-test.outputs.packages-to-jest-test }}'
env:
NODE_OPTIONS: '--max_old_space_size=4096'
YARN_ENABLE_IMMUTABLE_INSTALLS: false
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/pushDev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,8 @@ jobs:
${{ fromJson('[{"cmd":"packages/api-aco
--storage=ddb-es,ddb","storage":"ddb-es","packageName":"api-aco","id":"8f23ec33f547aa62236f5c71115688d6"},{"cmd":"packages/api-audit-logs
--storage=ddb-es,ddb","storage":"ddb-es","packageName":"api-audit-logs","id":"a292444cd9100f78d8fc196274393ea8"},{"cmd":"packages/api-dynamodb-to-elasticsearch
--storage=ddb-es,ddb","storage":["ddb-es"],"packageName":"api-dynamodb-to-elasticsearch","id":"e2c325f0940ba5fb5a891a8cf74fca61"},{"cmd":"packages/api-elasticsearch","storage":["ddb-es","ddb-os"],"packageName":"api-elasticsearch","id":"430874606aeb8e8041b325955f9330e3"},{"cmd":"packages/api-elasticsearch-tasks
--storage=ddb-es,ddb","storage":["ddb-es"],"packageName":"api-dynamodb-to-elasticsearch","id":"e2c325f0940ba5fb5a891a8cf74fca61"},{"cmd":"packages/api-elasticsearch
--storage=ddb-es,ddb","storage":["ddb-es"],"packageName":"api-elasticsearch","id":"5963079c60b96202bbaf2a802ad14383"},{"cmd":"packages/api-elasticsearch-tasks
--storage=ddb-es,ddb","storage":"ddb-es","packageName":"api-elasticsearch-tasks","id":"d81ad1d024a8746cc440e2e548770f8f"},{"cmd":"packages/api-file-manager
--storage=ddb-es,ddb","storage":"ddb-es","packageName":"api-file-manager","id":"d6f293add4a252b96cbd770ab6e80557"},{"cmd":"packages/api-form-builder
--storage=ddb-es,ddb","storage":"ddb-es","packageName":"api-form-builder","id":"3753bde0144d808eb15c755b7176386c"},{"cmd":"packages/api-form-builder-so-ddb-es
Expand Down Expand Up @@ -373,7 +374,8 @@ jobs:
${{ fromJson('[{"cmd":"packages/api-aco
--storage=ddb-os,ddb","storage":"ddb-os","packageName":"api-aco","id":"e4b1b5ebc172f2657485e41c35ad1cd7"},{"cmd":"packages/api-audit-logs
--storage=ddb-os,ddb","storage":"ddb-os","packageName":"api-audit-logs","id":"b36aac5f0e34dc4583e5422ae589f1ed"},{"cmd":"packages/api-dynamodb-to-elasticsearch
--storage=ddb-os,ddb","storage":["ddb-os"],"packageName":"api-dynamodb-to-elasticsearch","id":"6e0b282c3d135703e52b2c55822d4fb0"},{"cmd":"packages/api-elasticsearch","storage":["ddb-es","ddb-os"],"packageName":"api-elasticsearch","id":"430874606aeb8e8041b325955f9330e3"},{"cmd":"packages/api-elasticsearch-tasks
--storage=ddb-os,ddb","storage":["ddb-os"],"packageName":"api-dynamodb-to-elasticsearch","id":"6e0b282c3d135703e52b2c55822d4fb0"},{"cmd":"packages/api-elasticsearch
--storage=ddb-os,ddb","storage":["ddb-os"],"packageName":"api-elasticsearch","id":"b0f477d6b209f654714809b318be888e"},{"cmd":"packages/api-elasticsearch-tasks
--storage=ddb-os,ddb","storage":"ddb-os","packageName":"api-elasticsearch-tasks","id":"580a9577fdbd4a241034a42e1a47dee5"},{"cmd":"packages/api-file-manager
--storage=ddb-os,ddb","storage":"ddb-os","packageName":"api-file-manager","id":"346430a79981d3e214c87254a08e31b2"},{"cmd":"packages/api-form-builder
--storage=ddb-os,ddb","storage":"ddb-os","packageName":"api-form-builder","id":"d386cddfd3c366ad9955193dcfe74363"},{"cmd":"packages/api-form-builder-so-ddb-es
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/pushNext.yml
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,8 @@ jobs:
${{ fromJson('[{"cmd":"packages/api-aco
--storage=ddb-es,ddb","storage":"ddb-es","packageName":"api-aco","id":"8f23ec33f547aa62236f5c71115688d6"},{"cmd":"packages/api-audit-logs
--storage=ddb-es,ddb","storage":"ddb-es","packageName":"api-audit-logs","id":"a292444cd9100f78d8fc196274393ea8"},{"cmd":"packages/api-dynamodb-to-elasticsearch
--storage=ddb-es,ddb","storage":["ddb-es"],"packageName":"api-dynamodb-to-elasticsearch","id":"e2c325f0940ba5fb5a891a8cf74fca61"},{"cmd":"packages/api-elasticsearch","storage":["ddb-es","ddb-os"],"packageName":"api-elasticsearch","id":"430874606aeb8e8041b325955f9330e3"},{"cmd":"packages/api-elasticsearch-tasks
--storage=ddb-es,ddb","storage":["ddb-es"],"packageName":"api-dynamodb-to-elasticsearch","id":"e2c325f0940ba5fb5a891a8cf74fca61"},{"cmd":"packages/api-elasticsearch
--storage=ddb-es,ddb","storage":["ddb-es"],"packageName":"api-elasticsearch","id":"5963079c60b96202bbaf2a802ad14383"},{"cmd":"packages/api-elasticsearch-tasks
--storage=ddb-es,ddb","storage":"ddb-es","packageName":"api-elasticsearch-tasks","id":"d81ad1d024a8746cc440e2e548770f8f"},{"cmd":"packages/api-file-manager
--storage=ddb-es,ddb","storage":"ddb-es","packageName":"api-file-manager","id":"d6f293add4a252b96cbd770ab6e80557"},{"cmd":"packages/api-form-builder
--storage=ddb-es,ddb","storage":"ddb-es","packageName":"api-form-builder","id":"3753bde0144d808eb15c755b7176386c"},{"cmd":"packages/api-form-builder-so-ddb-es
Expand Down Expand Up @@ -373,7 +374,8 @@ jobs:
${{ fromJson('[{"cmd":"packages/api-aco
--storage=ddb-os,ddb","storage":"ddb-os","packageName":"api-aco","id":"e4b1b5ebc172f2657485e41c35ad1cd7"},{"cmd":"packages/api-audit-logs
--storage=ddb-os,ddb","storage":"ddb-os","packageName":"api-audit-logs","id":"b36aac5f0e34dc4583e5422ae589f1ed"},{"cmd":"packages/api-dynamodb-to-elasticsearch
--storage=ddb-os,ddb","storage":["ddb-os"],"packageName":"api-dynamodb-to-elasticsearch","id":"6e0b282c3d135703e52b2c55822d4fb0"},{"cmd":"packages/api-elasticsearch","storage":["ddb-es","ddb-os"],"packageName":"api-elasticsearch","id":"430874606aeb8e8041b325955f9330e3"},{"cmd":"packages/api-elasticsearch-tasks
--storage=ddb-os,ddb","storage":["ddb-os"],"packageName":"api-dynamodb-to-elasticsearch","id":"6e0b282c3d135703e52b2c55822d4fb0"},{"cmd":"packages/api-elasticsearch
--storage=ddb-os,ddb","storage":["ddb-os"],"packageName":"api-elasticsearch","id":"b0f477d6b209f654714809b318be888e"},{"cmd":"packages/api-elasticsearch-tasks
--storage=ddb-os,ddb","storage":"ddb-os","packageName":"api-elasticsearch-tasks","id":"580a9577fdbd4a241034a42e1a47dee5"},{"cmd":"packages/api-file-manager
--storage=ddb-os,ddb","storage":"ddb-os","packageName":"api-file-manager","id":"346430a79981d3e214c87254a08e31b2"},{"cmd":"packages/api-form-builder
--storage=ddb-os,ddb","storage":"ddb-os","packageName":"api-form-builder","id":"d386cddfd3c366ad9955193dcfe74363"},{"cmd":"packages/api-form-builder-so-ddb-es
Expand Down
23 changes: 20 additions & 3 deletions .github/workflows/wac/pullRequests.wac.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const createJestTestsJobs = (storage: string | null) => {
{
name: "Packages to test with Jest",
id: "list-packages",
run: "echo ${{ steps.list-packages-to-jest-test.outputs.packages-to-jest-test }}"
run: "echo '${{ steps.list-packages-to-jest-test.outputs.packages-to-jest-test }}'"
}
]
});
Expand Down Expand Up @@ -153,7 +153,9 @@ export const pullRequests = createWorkflow({
"global-cache-key": "${{ steps.global-cache-key.outputs.global-cache-key }}",
"run-cache-key": "${{ steps.run-cache-key.outputs.run-cache-key }}",
"is-fork-pr": "${{ steps.is-fork-pr.outputs.is-fork-pr }}",
"changed-packages": "${{ steps.detect-changed-packages.outputs.changed-packages }}"
"changed-packages": "${{ steps.detect-changed-packages.outputs.changed-packages }}",
"latest-webiny-version":
"${{ steps.latest-webiny-version.outputs.latest-webiny-version }}"
},
steps: [
{
Expand Down Expand Up @@ -197,6 +199,21 @@ export const pullRequests = createWorkflow({
"${{ steps.detect-changed-files.outputs.changed_files }}",
{ outputAs: "changed-packages" }
)
},
{
name: "Get latest Webiny version on NPM",
id: "latest-webiny-version",
run: addToOutputs("latest-webiny-version", "$(npm view @webiny/cli version)")
}
]
}),
assignMilestone: createJob({
name: "Assign milestone",
needs: "constants",
steps: [
{
name: "Print latest Webiny version",
run: "echo ${{ needs.constants.outputs.latest-webiny-version }}"
}
]
}),
Expand All @@ -216,7 +233,7 @@ export const pullRequests = createWorkflow({
]
}),
staticCodeAnalysis: createJob({
needs: ["constants", "build"],
needs: ["constants"],
name: "Static code analysis",
checkout: { path: DIR_WEBINY_JS },
steps: [
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/wac/utils/listPackagesWithJestTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,12 @@ const CUSTOM_HANDLERS: Record<string, () => Array<PackageWithTests>> = {
"api-elasticsearch": () => {
return [
{
cmd: "packages/api-elasticsearch",
storage: ["ddb-es", "ddb-os"]
cmd: "packages/api-elasticsearch --storage=ddb-es,ddb",
storage: ["ddb-es"]
},
{
cmd: "packages/api-elasticsearch --storage=ddb-os,ddb",
storage: ["ddb-os"]
}
];
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@babel/code-frame": "^7.26.2",
"@babel/compat-data": "^7.26.2",
"@babel/core": "^7.26.0",
"@babel/helper-define-polyfill-provider": "^0.6.2",
"@babel/helper-define-polyfill-provider": "^0.6.3",
"@babel/helper-environment-visitor": "^7.24.7",
"@babel/parser": "^7.26.2",
"@babel/plugin-proposal-class-properties": "^7.18.6",
Expand Down
10 changes: 9 additions & 1 deletion packages/api-dynamodb-to-elasticsearch/src/Operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,20 @@ export enum OperationType {
}

export class Operations implements IOperations {
public readonly items: GenericRecord[] = [];
private _items: GenericRecord[] = [];

public get items(): GenericRecord[] {
return this._items;
}

public get total(): number {
return this.items.length;
}

public clear() {
this._items = [];
}

public insert(params: IInsertOperationParams): void {
this.items.push(
{
Expand Down
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);
};
9 changes: 1 addition & 8 deletions packages/api-dynamodb-to-elasticsearch/src/eventHandler.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
import { getNumberEnvVariable } from "~/helpers/getNumberEnvVariable";
import { createDynamoDBEventHandler, timerFactory } from "@webiny/handler-aws";
import { Context } from "~/types";
import { Decompressor } from "~/Decompressor";
import { OperationsBuilder } from "~/OperationsBuilder";
import { executeWithRetry } from "~/executeWithRetry";
import { Context } from "~/types";

const MAX_PROCESSOR_PERCENT = getNumberEnvVariable(
"MAX_ES_PROCESSOR",
process.env.NODE_ENV === "test" ? 101 : 98
);

/**
* Also, we need to set the maximum running time for the Lambda Function.
Expand Down Expand Up @@ -49,7 +43,6 @@ export const createEventHandler = () => {
await executeWithRetry({
timer,
maxRunningTime: MAX_RUNNING_TIME,
maxProcessorPercent: MAX_PROCESSOR_PERCENT,
context,
operations
});
Expand Down
9 changes: 7 additions & 2 deletions packages/api-dynamodb-to-elasticsearch/src/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export interface IExecuteParams {
timer: ITimer;
maxRunningTime: number;
maxProcessorPercent: number;
context: Context;
operations: IOperations;
context: Pick<Context, "elasticsearch" | "logger">;
operations: Pick<IOperations, "items" | "total">;
}

const getError = (item: BulkOperationsResponseBodyItem): string | null => {
Expand Down Expand Up @@ -67,6 +67,11 @@ const checkErrors = (result?: ApiResponse<BulkOperationsResponseBody>): void =>
export const execute = (params: IExecuteParams) => {
return async (): Promise<void> => {
const { context, timer, maxRunningTime, maxProcessorPercent, operations } = params;

if (operations.total === 0) {
return;
}

const remainingTime = timer.getRemainingSeconds();
const runningTime = maxRunningTime - remainingTime;
const maxWaitingTime = remainingTime - 90;
Expand Down
Loading

0 comments on commit 3996f51

Please sign in to comment.