Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
marciocadev committed Jul 19, 2023
1 parent 0925b82 commit a98c3e1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
8 changes: 2 additions & 6 deletions libs/wingsdk/src/target-awscdk/schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,11 @@ export class Schedule extends cloud.Schedule {
let cronOpt: { [k: string]: string } = {
minute: cronArr[0],
hour: cronArr[1],
day: cronArr[2],
month: cronArr[3],
weekDay: cronArr[4],
year: "*",
};
if (cronArr[2] !== "?") {
cronOpt.day = cronArr[2];
}
if (cronArr[4] !== "?") {
cronOpt.weekDay = cronArr[4];
}

this.scheduleExpression = EventSchedule.cron(cronOpt);
} else {
Expand Down
14 changes: 14 additions & 0 deletions libs/wingsdk/test/target-awscdk/schedule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,17 @@ test("schedule with rate less than 1 minute", () => {
})
).toThrow("rate can not be set to less than 1 minute.");
});

test("cron with Day-of-month and Day-of-week setting with *", () => {
// GIVEN
const app = new awscdk.App({ outdir: mkdtemp(), ...CDK_APP_OPTS });

// THEN
expect(() =>
Schedule._newSchedule(app, "Schedule", {
cron: "0/1 * * * *",
})
).toThrow(
"cannot use * in both the Day-of-month and Day-of-week fields. If you use it in one, you must use ? in the other"
);
});

0 comments on commit a98c3e1

Please sign in to comment.