## Description This PR adds to the `estimate_billing` option to the `appsmithctl` command. This will help existing users estimate their bill when they consider upgrading to the paid edition. Usage: ``` appsmithctl estimate_billing Options: --sessionPrice The price per active session. Defaults to 0.3 --priceCap The price cap for a user in a given month. Defaults to 15 ``` A user can also run the command for various scenarios to determine the optimum capacity tier. ## Type of change - New feature (non-breaking change which adds functionality) - This change requires a documentation update ## How Has This Been Tested? Manually ## Checklist: - [ ] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes
92 lines
2.3 KiB
JavaScript
92 lines
2.3 KiB
JavaScript
const shell = require("shelljs");
|
|
const fsPromises = require("fs/promises");
|
|
const Constants = require("./constants");
|
|
const childProcess = require("child_process");
|
|
|
|
function showHelp() {
|
|
console.log(
|
|
"\nUsage: appsmith <command> to interact with appsmith utils tool"
|
|
);
|
|
console.log("\nOptions:\r");
|
|
console.log("\tex, export_db\t\tExport interal database.\r");
|
|
console.log("\tim, import_db\t\tImport interal database.\r");
|
|
console.log("\tmi, migrate\t\tMigrate new server.\r");
|
|
console.log("\tcrs, check_replica_set\tCheck replica set mongoDB.\r");
|
|
console.log("\tbackup\t\t\tTake a backup of Appsmith instance.\r");
|
|
console.log("\trestore\t\t\tRestore Appsmith instance from a backup.\r");
|
|
console.log("\testimate_billing\tEstimate billing based on past usage.\r");
|
|
console.log("\t--help\t\t\t" + "Show help.");
|
|
}
|
|
|
|
function stop(apps) {
|
|
const appsStr = apps.join(" ");
|
|
console.log("Stopping " + appsStr);
|
|
shell.exec("/usr/bin/supervisorctl stop " + appsStr);
|
|
console.log("Stopped " + appsStr);
|
|
}
|
|
|
|
function start(apps) {
|
|
const appsStr = apps.join(" ");
|
|
console.log("Starting " + appsStr);
|
|
shell.exec("/usr/bin/supervisorctl start " + appsStr);
|
|
console.log("Started " + appsStr);
|
|
}
|
|
|
|
function execCommand(cmd, options) {
|
|
return new Promise((resolve, reject) => {
|
|
let isPromiseDone = false;
|
|
|
|
const p = childProcess.spawn(cmd[0], cmd.slice(1), {
|
|
stdio: "inherit",
|
|
...options,
|
|
});
|
|
|
|
p.on("exit", (code) => {
|
|
if (isPromiseDone) {
|
|
return;
|
|
}
|
|
isPromiseDone = true;
|
|
if (code === 0) {
|
|
resolve();
|
|
} else {
|
|
reject();
|
|
}
|
|
});
|
|
|
|
p.on("error", (err) => {
|
|
if (isPromiseDone) {
|
|
return;
|
|
}
|
|
isPromiseDone = true;
|
|
log.error("Error running command", err);
|
|
reject();
|
|
});
|
|
});
|
|
}
|
|
|
|
async function listLocalBackupFiles() {
|
|
// Ascending order
|
|
const backupFiles = [];
|
|
await fsPromises
|
|
.readdir(Constants.BACKUP_PATH)
|
|
.then((filenames) => {
|
|
for (let filename of filenames) {
|
|
if (filename.match(/^appsmith-backup-.*\.tar\.gz$/)) {
|
|
backupFiles.push(filename);
|
|
}
|
|
}
|
|
})
|
|
.catch((err) => {
|
|
console.log(err);
|
|
});
|
|
return backupFiles;
|
|
}
|
|
|
|
module.exports = {
|
|
showHelp,
|
|
start,
|
|
stop,
|
|
execCommand,
|
|
listLocalBackupFiles,
|
|
};
|