"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 snip; (function (snip) { var db; (function (db) { class BupanDao extends snip.db.Dao { constructor() { super("aloewks_bupandb"); } } db.BupanDao = BupanDao; class BotActivity extends BupanDao { constructor(bot_id) { super(); this.bot_id = bot_id; } start() { return __awaiter(this, void 0, void 0, function* () { let now = snip.utils.date().format("yyyy-MM-dd hh:mm:ss"); return yield this.update("t_bot_activity", [{ "bot_id": this.bot_id, "requested_date": now, "statys": "running" }]).exec(); }); } completed() { return __awaiter(this, void 0, void 0, function* () { let now = snip.utils.date().format("yyyy-MM-dd hh:mm:ss"); return yield this.update("t_bot_activity", [{ "bot_id": this.bot_id, "executed_date": now, "status": "completed" }]).exec(); }); } failed() { return __awaiter(this, void 0, void 0, function* () { let now = snip.utils.date().format("yyyy-MM-dd hh:mm:ss"); return yield this.update("t_bot_activity", [{ "bot_id": this.bot_id, "executed_date": now, "status": "failed" }]).exec(); }); } status() { return __awaiter(this, void 0, void 0, function* () { return (yield this.query({ bot_id: this.bot_id }, function () { let a = snip.db.aloewks_bupandb.def.t_bot_activity("a"); let sql = db.select(a.status) + db.from(a) + db.where().eq(a.bot_id, db.BIND); return sql; }))[0]["status"]; }); } occurred(limit = 15) { return __awaiter(this, void 0, void 0, function* () { let last = yield this.query({ bot_id: this.bot_id }, function () { let a = snip.db.aloewks_bupandb.def.t_bot_activity("a"); let bf15min = snip.utils.date().addMinutes(-limit).format("yyyy-MM-dd hh:mm:ss"); let sql = db.select(a.status) + db.from(a) + db.where().eq(a.bot_id, db.BIND).more(a.executed_date, db.qt(bf15min)); console.log(sql); return sql; }); return last.length == 0 || last[0]["status"] == "failed"; }); } } db.BotActivity = BotActivity; $(function () { return __awaiter(this, void 0, void 0, function* () { let activity = new BotActivity("entrystop"); if (yield activity.occurred()) { $("#menu_activity").show().addClass("active red"); console.log("entrystop occered failure"); } else { $("#menu_activity").show(); } }); }); })(db = snip.db || (snip.db = {})); })(snip || (snip = {}));