From 687d7f7fe56a59fa89e09f8df32b3a2d2aa8869f Mon Sep 17 00:00:00 2001 From: Ben Limmer <630449+blimmer@users.noreply.github.com> Date: Tue, 8 Oct 2024 00:41:52 -0600 Subject: [PATCH] fix: pass ScheduleOffset config property and remove Timezone (#333) This PR: - removes the useless Timezone property (which was not passed through the ScheduleConfig anyway) - fixes the code to pass the `offset` property (which maps to `ScheduleOffset` in the L1 CFN resource) Fixes #345 --- API.md | 11 -- src/core/flows/flow-base.ts | 2 +- test/core/flows/on-schedule-flow.test.ts | 144 +++++++++++++++++++++++ 3 files changed, 145 insertions(+), 12 deletions(-) create mode 100644 test/core/flows/on-schedule-flow.test.ts diff --git a/API.md b/API.md index 138fec07..82181fa3 100644 --- a/API.md +++ b/API.md @@ -12425,7 +12425,6 @@ const scheduleProperties: ScheduleProperties = { ... } | firstExecutionFrom | Date | Timestamp for the records to import from the connector in the first flow run. | | offset | aws-cdk-lib.Duration | *No description.* | | startTime | Date | *No description.* | -| timezone | string | *No description.* | --- @@ -12472,16 +12471,6 @@ public readonly startTime: Date; --- -##### `timezone`Optional - -```typescript -public readonly timezone: string; -``` - -- *Type:* string - ---- - ### ServiceNowBasicSettings #### Initializer diff --git a/src/core/flows/flow-base.ts b/src/core/flows/flow-base.ts index 5837afa4..5bfcc86a 100644 --- a/src/core/flows/flow-base.ts +++ b/src/core/flows/flow-base.ts @@ -127,7 +127,6 @@ export interface ScheduleProperties { * @default 30 days back from the initial frow run */ readonly firstExecutionFrom?: Date; - readonly timezone?: string; } export interface TriggerProperties { @@ -304,6 +303,7 @@ export abstract class FlowBase extends Resource implements IFlow { Math.floor(props.properties.firstExecutionFrom.getTime() / 1000), scheduleStartTime: props.properties?.startTime && updater.startTime, scheduleEndTime: props.properties?.endTime && updater.endTime, + scheduleOffset: props.properties?.offset && props.properties.offset.toSeconds(), }; } diff --git a/test/core/flows/on-schedule-flow.test.ts b/test/core/flows/on-schedule-flow.test.ts new file mode 100644 index 00000000..3b5a3312 --- /dev/null +++ b/test/core/flows/on-schedule-flow.test.ts @@ -0,0 +1,144 @@ +/* +Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +SPDX-License-Identifier: Apache-2.0 +*/ +import { Duration, Stack } from 'aws-cdk-lib'; +import { Template } from 'aws-cdk-lib/assertions'; +import { Schedule } from 'aws-cdk-lib/aws-events'; +import { Key } from 'aws-cdk-lib/aws-kms'; +import { Bucket } from 'aws-cdk-lib/aws-s3'; +import { + S3Source, + S3Destination, + Mapping, + OnScheduleFlow, + DataPullMode, +} from '../../../src'; + +describe('OnScheduleFlow', () => { + test('', () => { + const stack = new Stack(undefined, 'TestStack'); + + const bucket = new Bucket(stack, 'TestBucket'); + + const source = new S3Source({ + bucket: bucket, + prefix: 'account', + }); + + const destination = new S3Destination({ + location: { bucket, prefix: 'new-account' }, + }); + + + new OnScheduleFlow(stack, 'OnScheduleFlow', { + source, + destination, + key: new Key(stack, 'TestKey'), + mappings: [Mapping.mapAll()], + schedule: Schedule.rate(Duration.days(1)), + pullConfig: { + mode: DataPullMode.INCREMENTAL, + }, + }); + + const template = Template.fromStack(stack); + + template.hasResourceProperties('AWS::AppFlow::Flow', { + DestinationFlowConfigList: [ + { + ConnectorType: 'S3', + DestinationConnectorProperties: { + S3: { + BucketName: { + Ref: 'TestBucket560B80BC', + }, + BucketPrefix: 'new-account', + }, + }, + }, + ], + FlowName: 'OnScheduleFlow', + SourceFlowConfig: { + ConnectorType: 'S3', + SourceConnectorProperties: { + S3: { + BucketName: { + Ref: 'TestBucket560B80BC', + }, + BucketPrefix: 'account', + }, + }, + }, + Tasks: [ + { + ConnectorOperator: { + S3: 'NO_OP', + }, + SourceFields: [], + TaskProperties: [ + { + Key: 'EXCLUDE_SOURCE_FIELDS_LIST', + Value: '[]', + }, + ], + TaskType: 'Map_all', + }, + ], + TriggerConfig: { + TriggerType: 'Scheduled', + TriggerProperties: { + DataPullMode: 'Incremental', + }, + }, + KMSArn: { + 'Fn::GetAtt': [ + 'TestKey4CACAF33', + 'Arn', + ], + }, + }); + }); + + test('it passes offset', () => { + const stack = new Stack(undefined, 'TestStack'); + + const bucket = new Bucket(stack, 'TestBucket'); + + const source = new S3Source({ + bucket: bucket, + prefix: 'account', + }); + + const destination = new S3Destination({ + location: { bucket, prefix: 'new-account' }, + }); + + + new OnScheduleFlow(stack, 'OnScheduleFlow', { + source, + destination, + mappings: [Mapping.mapAll()], + schedule: Schedule.rate(Duration.days(1)), + pullConfig: { + mode: DataPullMode.INCREMENTAL, + }, + scheduleProperties: { + offset: Duration.hours(1), + }, + }); + + const template = Template.fromStack(stack); + + template.hasResourceProperties('AWS::AppFlow::Flow', { + FlowName: 'OnScheduleFlow', + TriggerConfig: { + TriggerType: 'Scheduled', + TriggerProperties: { + DataPullMode: 'Incremental', + ScheduleOffset: 3600, + }, + }, + }); + }); +});