@grouparoo/core
Version:
The Grouparoo Core
59 lines (58 loc) • 2.35 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PrivateStatus = exports.PublicStatus = void 0;
const actionhero_1 = require("actionhero");
const path_1 = __importDefault(require("path"));
const Setting_1 = require("../models/Setting");
const authenticatedAction_1 = require("../classes/actions/authenticatedAction");
const status_1 = require("../modules/status");
const runMode_1 = require("../modules/runMode");
const packageJSON = require(path_1.default.join(__dirname, "..", "..", "package.json"));
class PublicStatus extends actionhero_1.Action {
constructor() {
super(...arguments);
this.name = "status:public";
this.description = "A basic status endpoint";
this.outputExample = {};
}
async run() {
return { status: "ok" };
}
}
exports.PublicStatus = PublicStatus;
class PrivateStatus extends authenticatedAction_1.AuthenticatedAction {
constructor() {
super(...arguments);
this.name = "status:private";
this.description = "I will return detailed information about this API server and Resque";
this.permission = { topic: "system", mode: "read" };
this.outputExample = {};
}
async runWithinTransaction() {
const clusterName = (await Setting_1.Setting.findOne({
where: { pluginName: "core", key: "cluster-name" },
})).value;
const samples = await status_1.Status.get();
const { leader } = await actionhero_1.task.details();
const runMode = (0, runMode_1.getGrouparooRunMode)();
if (!leader && runMode === "cli:start") {
throw new Error(`no leader for this Grouparoo cluster "${clusterName}" (${runMode})`);
}
return {
clusterName,
id: actionhero_1.id,
actionheroVersion: actionhero_1.actionheroVersion,
packageName: packageJSON.name,
description: packageJSON.description,
version: packageJSON.version,
runMode,
uptime: new Date().getTime() - actionhero_1.api.bootTime,
metrics: samples,
leader,
};
}
}
exports.PrivateStatus = PrivateStatus;