@grouparoo/core
Version:
The Grouparoo Core
32 lines (31 loc) • 1.37 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AppRefreshQueriesCheck = void 0;
const clsTask_1 = require("../../classes/tasks/clsTask");
const AppRefreshQuery_1 = require("../../models/AppRefreshQuery");
const cls_1 = require("../../modules/cls");
const runMode_1 = require("../../modules/runMode");
class AppRefreshQueriesCheck extends clsTask_1.CLSTask {
constructor() {
super(...arguments);
this.name = "appRefreshQueries:check";
this.description = "check all appRefreshQueries and run them";
this.frequency = (0, runMode_1.getGrouparooRunMode)() === "cli:run" ? 0 : 1000 * 60; // Run every minute
this.queue = "apps";
}
async runWithinTransaction() {
const appRefreshQueries = await AppRefreshQuery_1.AppRefreshQuery.findAll();
for (const appRefreshQuery of appRefreshQueries) {
const shouldRun = await appRefreshQuery.shouldRun();
if (shouldRun) {
const app = appRefreshQuery.$get("app", { where: { state: "ready" } });
if (app) {
await cls_1.CLS.enqueueTask("appRefreshQuery:run", {
appRefreshQueryId: appRefreshQuery.id,
});
}
}
}
}
}
exports.AppRefreshQueriesCheck = AppRefreshQueriesCheck;