Skip to content

Commit

Permalink
Merge pull request #48 from RenovoSolutions/refactor
Browse files Browse the repository at this point in the history
refactor: Use one time events library instead of own function
  • Loading branch information
bmiller08 authored Oct 18, 2021
2 parents ed6fb75 + 9924394 commit 2784cb4
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .projen/deps.json

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

2 changes: 1 addition & 1 deletion .projen/tasks.json

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

3 changes: 3 additions & 0 deletions .projenrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ const project = new AwsCdkConstructLibrary({
'@aws-cdk/aws-sns-subscriptions',
'@aws-cdk/aws-route53',
],
deps: [
'@renovosolutions/cdk-library-one-time-event@^0.0.2',
],
keywords: [
'letsencrypt',
'certbot',
Expand Down
3 changes: 2 additions & 1 deletion package.json

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

20 changes: 4 additions & 16 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as s3 from '@aws-cdk/aws-s3';
import * as sns from '@aws-cdk/aws-sns';
import * as subscriptions from '@aws-cdk/aws-sns-subscriptions';
import * as cdk from '@aws-cdk/core';
import * as oneTimeEvents from '@renovosolutions/cdk-library-one-time-event';

export interface ICertbotProps {
/**
Expand Down Expand Up @@ -206,23 +207,10 @@ export class Certbot extends cdk.Construct {
});

if (props.runOnDeploy) {
const dateToCron = (date:Date) => {
const minutesToAdd = props.runOnDeployWaitMinutes || 10;
const future = new Date(date.getTime() + minutesToAdd * 60000);
const minutes = future.getUTCMinutes();
const hours = future.getUTCHours();
const days = future.getUTCDate();
const months = future.getUTCMonth() + 1;
const dayOfWeek = '?';
const years = future.getUTCFullYear();

return `${minutes} ${hours} ${days} ${months} ${dayOfWeek} ${years}`;
};

const oneTimeSchedule = events.Schedule.expression('cron(' + dateToCron(new Date()) + ')');

new events.Rule(this, 'triggerImmediate', {
schedule: oneTimeSchedule,
schedule: new oneTimeEvents.OnDeploy(this, 'schedule', {
offsetMinutes: 10,
}).schedule,
targets: [new targets.LambdaFunction(this.handler)],
});
}
Expand Down
8 changes: 8 additions & 0 deletions yarn.lock

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

0 comments on commit 2784cb4

Please sign in to comment.