Browse Source

logz

bugfix/timeout-logging
Evan Feenstra 5 years ago
parent
commit
9bfb3b130d
  1. 15
      api/utils/timers.ts
  2. 13
      dist/api/utils/timers.js
  3. 2
      dist/api/utils/timers.js.map

15
api/utils/timers.ts

@ -45,25 +45,32 @@ function makeName(t){
} }
export async function reloadTimers(){ export async function reloadTimers(){
const timers = await models.Timer.findAll() console.log("reload timers")
timers && timers.forEach(t=>{ const timers = await models.Timer.findAll()
console.log('timers.length',timers.length)
timers && timers.forEach((t,i)=>{
const name = makeName(t) const name = makeName(t)
setTimer(name, t.millis, async ()=>{ setTimer(name, t.millis, async ()=>{
payBack(t) setTimeout(()=>{
payBack(t)
},i*250) // dont do all at once
}) })
}) })
} }
export async function payBack(t){ export async function payBack(t){
console.log('pay back')
const chat = await models.Chat.findOne({ where: {id:t.chatId} }) const chat = await models.Chat.findOne({ where: {id:t.chatId} })
const owner = await models.Contact.findOne({ where: {isOwner:true} }) const owner = await models.Contact.findOne({ where: {isOwner:true} })
console.log('is a chat?',chat.id)
if(!chat) return if(!chat) return
const theChat = {...chat.dataValues, contactIds:[t.receiver]} const theChat = {...chat.dataValues, contactIds:[t.receiver]}
console.log('send msg',{id:t.msgId})
network.sendMessage({ network.sendMessage({
chat: theChat, chat: theChat,
sender: owner, sender: owner,
message: {id:t.msgId}, message: {id:t.msgId},
amount: t.amount, amount: t.amount,
type: constants.message_types.confirmation, type: constants.message_types.direct_payment,
}) })
models.Timer.destroy({where:{id:t.id}}) models.Timer.destroy({where:{id:t.id}})
} }

13
dist/api/utils/timers.js

@ -66,11 +66,15 @@ function makeName(t) {
} }
function reloadTimers() { function reloadTimers() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
console.log("reload timers");
const timers = yield models_1.models.Timer.findAll(); const timers = yield models_1.models.Timer.findAll();
timers && timers.forEach(t => { console.log('timers.length', timers.length);
timers && timers.forEach((t, i) => {
const name = makeName(t); const name = makeName(t);
setTimer(name, t.millis, () => __awaiter(this, void 0, void 0, function* () { setTimer(name, t.millis, () => __awaiter(this, void 0, void 0, function* () {
payBack(t); setTimeout(() => {
payBack(t);
}, i * 250); // dont do all at once
})); }));
}); });
}); });
@ -78,17 +82,20 @@ function reloadTimers() {
exports.reloadTimers = reloadTimers; exports.reloadTimers = reloadTimers;
function payBack(t) { function payBack(t) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
console.log('pay back');
const chat = yield models_1.models.Chat.findOne({ where: { id: t.chatId } }); const chat = yield models_1.models.Chat.findOne({ where: { id: t.chatId } });
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } }); const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } });
console.log('is a chat?', chat.id);
if (!chat) if (!chat)
return; return;
const theChat = Object.assign(Object.assign({}, chat.dataValues), { contactIds: [t.receiver] }); const theChat = Object.assign(Object.assign({}, chat.dataValues), { contactIds: [t.receiver] });
console.log('send msg', { id: t.msgId });
network.sendMessage({ network.sendMessage({
chat: theChat, chat: theChat,
sender: owner, sender: owner,
message: { id: t.msgId }, message: { id: t.msgId },
amount: t.amount, amount: t.amount,
type: constants.message_types.confirmation, type: constants.message_types.direct_payment,
}); });
models_1.models.Timer.destroy({ where: { id: t.id } }); models_1.models.Timer.destroy({ where: { id: t.id } });
}); });

2
dist/api/utils/timers.js.map

@ -1 +1 @@
{"version":3,"file":"timers.js","sourceRoot":"","sources":["../../../api/utils/timers.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,sCAAkC;AAClC,sCAAqC;AACrC,6BAA4B;AAE5B,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAC,6BAA6B,CAAC,CAAC,CAAA;AAE7E,MAAM,MAAM,GAAC,EAAE,CAAA;AACf,SAAS,UAAU,CAAC,CAAC;IACjB,MAAM,IAAI,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAA;IACxB,IAAG,IAAI;QAAE,YAAY,CAAC,MAAM,CA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