UNPKG

@grouparoo/core

Version:
36 lines (35 loc) 1.38 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AppRefreshQueryRun = void 0; const clsTask_1 = require("../../classes/tasks/clsTask"); const AppRefreshQuery_1 = require("../../models/AppRefreshQuery"); class AppRefreshQueryRun extends clsTask_1.CLSTask { constructor() { super(...arguments); this.name = "appRefreshQuery:run"; this.description = "run a single appRefreshQuery and update values/trigger schedules if needed"; this.frequency = 0; this.queue = "apps"; this.inputs = { appRefreshQueryId: { required: true } }; } async runWithinTransaction({ appRefreshQueryId, }) { const appRefreshQuery = await AppRefreshQuery_1.AppRefreshQuery.findOne({ where: { id: appRefreshQueryId }, }); if (!appRefreshQuery) return; const sampleValue = await appRefreshQuery.query(); if (sampleValue !== appRefreshQuery.value) { await appRefreshQuery.triggerSchedules(); await appRefreshQuery.update({ value: sampleValue, lastChangedAt: new Date(), lastConfirmedAt: new Date(), }); } else { await appRefreshQuery.update({ lastConfirmedAt: new Date() }); } } } exports.AppRefreshQueryRun = AppRefreshQueryRun;