mup-aws-beanstalk
Version:
Deploy apps to AWS Elastic Beanstalk using Meteor Up
121 lines (102 loc) • 3.04 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getLastEvent = getLastEvent;
exports.showEvents = showEvents;
exports.waitForEnvReady = waitForEnvReady;
exports.waitForHealth = waitForHealth;
var _utils = require("./utils");
var _aws = require("./aws");
var _recheck = require("./recheck");
async function getLastEvent(config) {
const {
environment
} = (0, _utils.names)(config);
const {
Events
} = await _aws.beanstalk.describeEvents({
EnvironmentName: environment,
MaxRecords: 5
}).promise();
return Events[0].EventDate;
}
async function showEvents(config, lastEventDate) {
const {
environment,
app
} = (0, _utils.names)(config);
const {
Events
} = await _aws.beanstalk.describeEvents({
EnvironmentName: environment,
ApplicationName: app,
StartTime: lastEventDate
}).promise();
Events.forEach(event => {
if (event.EventDate.toString() === lastEventDate.toString()) {
return;
}
console.log(` Env Event: ${event.Message}`);
});
return new Date(Events[0].EventDate);
}
async function checker(config, prop, wantedValue, showProgress) {
const {
environment,
app
} = (0, _utils.names)(config);
let lastEventDate = null;
let lastStatus = null;
if (showProgress) {
lastEventDate = await getLastEvent(config);
}
return new Promise((resolve, reject) => {
async function check() {
let result;
try {
result = await _aws.beanstalk.describeEnvironments({
EnvironmentNames: [environment],
ApplicationName: app
}).promise();
} catch (e) {
if ((0, _recheck.checkForThrottlingException)(e)) {
(0, _recheck.handleThrottlingException)();
return setTimeout(check, (0, _recheck.getRecheckInterval)());
}
console.log(e);
reject(e);
}
const value = result.Environments[0][prop];
if (value !== wantedValue && value !== lastStatus) {
const text = prop === 'Health' ? `be ${wantedValue}` : `finish ${value}`;
(0, _utils.logStep)(`=> Waiting for Beanstalk environment to ${text.toLocaleLowerCase()}`);
lastStatus = value;
} else if (value === wantedValue) {
// TODO: run showEvents one last time
resolve();
return;
}
if (showProgress) {
try {
lastEventDate = await showEvents(config, lastEventDate);
} catch (e) {
if ((0, _recheck.checkForThrottlingException)(e)) {
(0, _recheck.handleThrottlingException)();
} else {
console.log(e);
}
}
}
setTimeout(check, (0, _recheck.getRecheckInterval)());
}
check();
});
}
async function waitForEnvReady(config, showProgress) {
await checker(config, 'Status', 'Ready', showProgress);
}
async function waitForHealth(config, health = 'Green', showProgress) {
await checker(config, 'Health', health, showProgress);
}
//# sourceMappingURL=env-ready.js.map
;