mirror of
https://github.com/serverless/serverless.git
synced 2026-01-18 14:58:43 +00:00
Fix `print` The print command is highly linked to the `Variables` and `Service` codebases, keep those in sync and leave reminders about the link. Made these explicit and separately implemented to avoid complexity. Additionally, the print command re-populates an object with the *very similar* content as the previously pre-populated service (just not augmented as just mentioned). This can lead to cross contamination between the two. As such, all caches must be cleared per unique invocation of service/object/property population. Add tests for some expected but previously unverified behaviors. Clean pre-population The previous implementation worked okay but was unnecessary and would have been a maintenance problem. Instead, just knock out the population of variables depending on those config dependent services and use the standard means of resolution. Fix cyclic bug (resulting from running print against a self-referencing serverless.yml) The caching of values could lead to a cyclic object remaining in the caches for variable population. This causes crashes and pain. Solved by the cache cleaning logic.
59 lines
1.8 KiB
JavaScript
59 lines
1.8 KiB
JavaScript
'use strict';
|
|
|
|
const logWarning = require('./Error').logWarning;
|
|
|
|
class PromiseTracker {
|
|
constructor() {
|
|
this.reset();
|
|
}
|
|
reset() {
|
|
this.promiseList = [];
|
|
this.promiseMap = {};
|
|
this.startTime = Date.now();
|
|
}
|
|
start() {
|
|
this.reset();
|
|
this.interval = setInterval(this.report.bind(this), 2500);
|
|
}
|
|
report() {
|
|
const delta = Date.now() - this.startTime;
|
|
logWarning('################################################################################');
|
|
logWarning(`# ${delta}: ${this.getSettled().length} of ${
|
|
this.getAll().length} promises have settled`);
|
|
const pending = this.getPending();
|
|
logWarning(`# ${delta}: ${pending.length} unsettled promises:`);
|
|
pending.forEach((promise) => {
|
|
logWarning(`# ${delta}: ${promise.waitList}`);
|
|
});
|
|
logWarning('################################################################################');
|
|
}
|
|
stop() {
|
|
clearInterval(this.interval);
|
|
this.reset();
|
|
}
|
|
add(variable, prms, specifier) {
|
|
const promise = prms;
|
|
promise.waitList = `${variable} waited on by: ${specifier}`;
|
|
promise.state = 'pending';
|
|
promise.then( // creates a promise with the following effects but that we otherwise ignore
|
|
() => { promise.state = 'resolved'; },
|
|
() => { promise.state = 'rejected'; });
|
|
this.promiseList.push(promise);
|
|
this.promiseMap[variable] = promise;
|
|
return promise;
|
|
}
|
|
contains(variable) {
|
|
return variable in this.promiseMap;
|
|
}
|
|
get(variable, specifier) {
|
|
const promise = this.promiseMap[variable];
|
|
promise.waitList += ` ${specifier}`;
|
|
return promise;
|
|
}
|
|
getPending() { return this.promiseList.filter(p => (p.state === 'pending')); }
|
|
getSettled() { return this.promiseList.filter(p => (p.state !== 'pending')); }
|
|
getAll() { return this.promiseList; }
|
|
}
|
|
|
|
module.exports = PromiseTracker;
|