phx-node-test-1
Version:
PHX NODE
94 lines • 4.45 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var PHXSentryMonitorService_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PHXSentryMonitorService = void 0;
const common_1 = require("@nestjs/common");
const Sentry = require("@sentry/nestjs");
const constant_1 = require("../../lib/constant");
let PHXSentryMonitorService = PHXSentryMonitorService_1 = class PHXSentryMonitorService {
constructor() {
this.logger = new common_1.Logger(PHXSentryMonitorService_1.name);
}
checkInSentry(cronTime, taskService, monitorConfig, monitorSlug, hostName) {
return __awaiter(this, void 0, void 0, function* () {
try {
const cronTask = () => __awaiter(this, void 0, void 0, function* () {
this.logger.log(`[${monitorSlug}] cron job is running...`);
yield taskService.init(hostName);
});
yield this.runWithSentryCheckIn(monitorSlug, cronTime, cronTask, monitorConfig);
}
catch (err) {
this.logger.error(err);
}
});
}
runWithSentryCheckIn(monitorSlug, cronTime, cronTask, monitorConfig) {
return __awaiter(this, void 0, void 0, function* () {
this.logger.debug(process.env.ENV);
if (process.env.ENV === constant_1.envProd) {
const { checkInMargin, maxRuntime } = monitorConfig;
console.log("monitorConfig", monitorConfig);
const checkInId = Sentry.captureCheckIn({
monitorSlug,
status: "in_progress",
}, {
schedule: {
type: "crontab",
value: cronTime,
},
checkinMargin: checkInMargin,
maxRuntime,
failureIssueThreshold: 3,
});
this.logger.debug(checkInId);
try {
yield cronTask();
const res = Sentry.captureCheckIn({
checkInId,
monitorSlug,
status: "ok",
});
this.logger.debug(res);
}
catch (err) {
Sentry.withScope((scope) => {
scope.setTag("errorType", "catch");
Sentry.captureException(err);
Sentry.captureCheckIn({
checkInId,
monitorSlug,
status: "error",
});
});
this.logger.debug(err);
throw new Error(err);
}
}
else {
this.logger.debug("Ko checkin Sentry");
yield cronTask();
}
});
}
};
exports.PHXSentryMonitorService = PHXSentryMonitorService;
exports.PHXSentryMonitorService = PHXSentryMonitorService = PHXSentryMonitorService_1 = __decorate([
(0, common_1.Injectable)()
], PHXSentryMonitorService);
//# sourceMappingURL=sentry.service.js.map