Skip to content

Commit

Permalink
fix: pass ScheduleOffset config property and remove Timezone (#333)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
blimmer authored Oct 8, 2024
1 parent 41b3e6f commit 687d7f7
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 12 deletions.
11 changes: 0 additions & 11 deletions API.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/core/flows/flow-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(),
};
}

Expand Down
144 changes: 144 additions & 0 deletions test/core/flows/on-schedule-flow.test.ts
Original file line number Diff line number Diff line change
@@ -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,
},
},
});
});
});

0 comments on commit 687d7f7

Please sign in to comment.