Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add autoDomain and autoDomainWaitFor option to config #356

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 11 additions & 9 deletions src/index.ts
Expand Up @@ -142,15 +142,17 @@ class ServerlessCustomDomain {
await this.getDomainInfo();

if (autoDomain === true) {
const atLeastOneDoesNotExist = this.domains.some((domain) => !domain.domainInfo);
if (atLeastOneDoesNotExist === true) {
const waitFor =
parseInt(this.serverless.service.custom.customDomain.autoDomainWaitFor, 10)
|| 120;
this.serverless.cli.log(`Waiting ${waitFor} seconds before starting deployment
because first time creating domain`);

await sleep(waitFor);
const atLeastOneDoesNotExist = () => this.domains.some((domain) => !domain.domainInfo);
const maxWaitFor = parseInt(this.serverless.service.custom.customDomain.autoDomainWaitFor, 10) || 120;
const pollInterval = 3;
for (let i = 0; i * pollInterval < maxWaitFor && atLeastOneDoesNotExist() === true; i++) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we exit this for loop?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if all domains exist , then atLeastOneDoesNotExist() will be false and exit (await this.getDomainInfo(); in the for loop will repopulate data so it can go from true/false)

otherwise, if it never populates, the i * pollInterval will eventually be greater than maxWaitFor and it'll exit and the deployment will eventually fail in the same way as if you never ran create_domain

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jconstance-amplify let me know what you think :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jconstance-amplify no vacations allowed!!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fortunately for you I came back on Monday! :D

this.serverless.cli.log(`
Poll #${i + 1}: polling every ${pollInterval} seconds
for domain to exist or until ${maxWaitFor} seconds
have elapsed before starting deployment
`);

await sleep(pollInterval);
await this.getDomainInfo();
}
}
Expand Down