UNPKG

@ckstack/ck-push-retry

Version:

ckstack push retry server module

74 lines (73 loc) 4.16 kB
"use strict"; 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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.startServer = void 0; const bluebird_1 = require("bluebird"); const dk_lib_1 = require("@dkpkg/dk-lib"); const ck_lib_sequelize_1 = require("@ckstack/ck-lib-sequelize"); const ck_lib_gw_1 = require("@ckstack/ck-lib-gw"); const dk_lib_cron_1 = require("@dkpkg/dk-lib-cron"); const dk_lib_slack_1 = require("@dkpkg/dk-lib-slack"); const dk_lib_rmq_1 = require("@dkpkg/dk-lib-rmq"); const MyConfig_1 = require("./MyConfig"); const MyValues_1 = require("./MyValues"); const RetryDelayAwsSqs_1 = __importDefault(require("./service/RetryDelayAwsSqs")); const RetryDelayRmq_1 = __importDefault(require("./service/RetryDelayRmq")); const startServer = () => { bluebird_1.Promise.resolve() .then(() => { dk_lib_1.CkTime.init(MyConfig_1.conf.TZ); if (MyConfig_1.conf.SLACK_WEBHOOK_USE) { dk_lib_slack_1.CkSlack.init(MyConfig_1.conf.SLACK_WEBHOOK_URL, MyConfig_1.conf.SLACK_WEBHOOK_MSG_PRETEXT, MyConfig_1.conf.SLACK_WEBHOOK_MSG_TITLE); } }) .then(() => __awaiter(void 0, void 0, void 0, function* () { if (MyConfig_1.conf.DB_INFO.length <= 0 && MyConfig_1.conf.TUNNEL_DB_INFO.length <= 0) { dk_lib_1.CkLogger.errLog2(`not found database config. conf.DB_INFO.length [${MyConfig_1.conf.DB_INFO.length}], conf.TUNNEL_DB_INFO.length [${MyConfig_1.conf.TUNNEL_DB_INFO.length}]`, MyValues_1.PROC_LHD.LHD); yield dk_lib_slack_1.CkSlack.sendMessageServerStartFailAndProcessKill('not found database config'); } if (MyConfig_1.conf.DB_INFO.length > 0) { MyConfig_1.conf.DB_INFO[0].MODEL_ABS_PATH = `${ck_lib_sequelize_1.CkDBType.TABLE_TYPE.PUSH_TABLE_MODEL}`; } if (MyConfig_1.conf.TUNNEL_DB_INFO.length > 0) { MyConfig_1.conf.TUNNEL_DB_INFO[0].MODEL_ABS_PATH = `${ck_lib_sequelize_1.CkDBType.TABLE_TYPE.PUSH_TABLE_MODEL}`; } return ck_lib_gw_1.CkExpress.runWebServerType2(MyConfig_1.conf, []); })) .then(() => { if (MyConfig_1.conf.HTF_DELAY_VENDOR === dk_lib_1.CkValue.DELAY_VENDOR_TYPE.AWS_SQS) { dk_lib_cron_1.CkCronService.init([ { taskObj: new RetryDelayAwsSqs_1.default(), schedule: '*/10 * * * * *', }, ]); setTimeout(() => { dk_lib_1.CkLogger.infoLog('start aws sqs polling cron - onStart', MyValues_1.PROC_LHD.LHD); dk_lib_cron_1.CkCronService.start(); }, 10000); } else { setTimeout(() => { dk_lib_1.CkLogger.infoLog('registered rabbitmq receive listener for delayed rabbitmq', MyValues_1.PROC_LHD.LHD); dk_lib_rmq_1.CkRabbitMQ.registReceiveDelayMessageCallback(MyConfig_1.conf.HTF_DELAY_VENDOR_RMQ_QUEUE, RetryDelayRmq_1.default.onMessage, false); }, 10000); } }) .catch((err) => __awaiter(void 0, void 0, void 0, function* () { dk_lib_1.CkLogger.errLog(`can't start process. unhandled error [${err.toString()}]. process terminate.`, MyValues_1.PROC_LHD.LHD); yield dk_lib_slack_1.CkSlack.sendMessageServerStartFailAndProcessKill("can't start process. unhandled error"); })); }; exports.startServer = startServer;