@grouparoo/core
Version:
The Grouparoo Core
56 lines (55 loc) • 2.34 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GrouparooRPC = void 0;
const actionhero_1 = require("actionhero");
const App_1 = require("../models/App");
const appsCache_1 = require("../modules/caches/appsCache");
const sourcesCache_1 = require("../modules/caches/sourcesCache");
const propertiesCache_1 = require("../modules/caches/propertiesCache");
const destinationsCache_1 = require("../modules/caches/destinationsCache");
const modelsCache_1 = require("../modules/caches/modelsCache");
class GrouparooRPC extends actionhero_1.Initializer {
constructor() {
super();
this.name = "grouparooRPC";
this.loadPriority = 10;
this.stopPriority = 901;
}
async initialize() {
/**
* Here is where we list methods which will be invoked by `api.doCluster`
*/
actionhero_1.api.rpc = {
model: {},
app: {},
source: {},
property: {},
destination: {},
};
/**
* All handlers need start with a sleep() to decouple from mock redis' callback/transaction chain (there's no delay), or have no side-effects
*/
/**
* Signal that all Apps in the cluster should disconnect form persistent connections.
*/
actionhero_1.api.rpc.app.disconnect = async (appId) => {
var _a;
await actionhero_1.utils.sleep(100);
try {
await App_1.App.disconnect(appId);
}
catch (error) {
(0, actionhero_1.log)((_a = "Error disconnecting apps: " + error.message) !== null && _a !== void 0 ? _a : error);
}
};
/**
* Clear the caches
*/
actionhero_1.api.rpc.model.invalidateCache = () => modelsCache_1.ModelsCache.invalidate();
actionhero_1.api.rpc.app.invalidateCache = () => appsCache_1.AppsCache.invalidate();
actionhero_1.api.rpc.source.invalidateCache = () => sourcesCache_1.SourcesCache.invalidate();
actionhero_1.api.rpc.property.invalidateCache = () => propertiesCache_1.PropertiesCache.invalidate();
actionhero_1.api.rpc.destination.invalidateCache = () => destinationsCache_1.DestinationsCache.invalidate();
}
}
exports.GrouparooRPC = GrouparooRPC;