Browse Source

healthcheck 200

loopout2
Evan Feenstra 5 years ago
parent
commit
beaf8526b6
  1. 6
      dist/src/controllers/confirmations.js
  2. 2
      dist/src/controllers/confirmations.js.map
  3. 9
      dist/src/utils/res.js
  4. 2
      dist/src/utils/res.js.map
  5. 24
      src/controllers/confirmations.ts
  6. 11
      src/utils/res.ts

6
dist/src/controllers/confirmations.js

@ -150,7 +150,7 @@ function healthcheck(req, res) {
return __awaiter(this, void 0, void 0, function* () {
const pubkey = req.query.pubkey;
if (!(pubkey && pubkey.length === 66)) {
return res_1.failure(res, 'missing pubkey');
return res_1.failure200(res, 'missing pubkey');
}
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } });
const amt = 10;
@ -169,7 +169,7 @@ function healthcheck(req, res) {
yield network.signAndSend(opts);
}
catch (e) {
res_1.failure(res, e);
res_1.failure200(res, e);
return;
}
let i = 0;
@ -177,7 +177,7 @@ function healthcheck(req, res) {
if (i >= 15) {
clearInterval(interval);
delete heartbeats[pubkey];
res_1.failure(res, 'no confimration received');
res_1.failure200(res, 'no confimration received');
return;
}
if (heartbeats[pubkey]) {

2
dist/src/controllers/confirmations.js.map

File diff suppressed because one or more lines are too long

9
dist/src/utils/res.js

@ -18,4 +18,13 @@ function failure(res, e) {
res.end();
}
exports.failure = failure;
function failure200(res, e) {
res.status(200);
res.json({
success: false,
error: (e && e.message) || e,
});
res.end();
}
exports.failure200 = failure200;
//# sourceMappingURL=res.js.map

2
dist/src/utils/res.js.map

@ -1 +1 @@
{"version":3,"file":"res.js","sourceRoot":"","sources":["../../../src/utils/res.ts"],"names":[],"mappings":";;AAAA,SAAS,OAAO,CAAC,GAAG,EAAE,IAAI;IACxB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAChB,GAAG,CAAC,IAAI,CAAC;QACP,OAAO,EAAE,IAAI;QACb,QAAQ,EAAE,IAAI;KACf,CAAC,CAAC;IACH,GAAG,CAAC,GAAG,EAAE,CAAC;AACZ,CAAC;AAWO,0B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4,7 @@ import * as socket from '../utils/socket'
import * as jsonUtils from '../utils/json'
import * as network from '../network'
import constants from '../constants'
import { failure, success } from '../utils/res'
import { success, failure200 } from '../utils/res'
export function sendConfirmation({ chat, sender, msg_id }) {
if (!msg_id) return
@ -112,7 +112,7 @@ export async function receiveHeartbeat(payload) {
const owner = await models.Contact.findOne({ where: { isOwner: true } })
const amount = Math.round(receivedAmount/2)
const amount = Math.round(receivedAmount / 2)
const amt = Math.max(amount || constants.min_sat_amount)
const opts = {
amt,
@ -131,11 +131,11 @@ export async function receiveHeartbeat(payload) {
}
}
let heartbeats:{[k:string]:boolean} = {}
let heartbeats: { [k: string]: boolean } = {}
export async function healthcheck(req, res) {
const pubkey:string = req.query.pubkey
if (!(pubkey&&pubkey.length===66)) {
return failure(res, 'missing pubkey')
const pubkey: string = req.query.pubkey
if (!(pubkey && pubkey.length === 66)) {
return failure200(res, 'missing pubkey')
}
const owner = await models.Contact.findOne({ where: { isOwner: true } })
@ -155,25 +155,25 @@ export async function healthcheck(req, res) {
try {
await network.signAndSend(opts)
} catch (e) {
failure(res, e)
failure200(res, e)
return
}
let i = 0
let interval = setInterval(()=>{
if(i>=15) {
let interval = setInterval(() => {
if (i >= 15) {
clearInterval(interval)
delete heartbeats[pubkey]
failure(res, 'no confimration received')
failure200(res, 'no confimration received')
return
}
if(heartbeats[pubkey]) {
if (heartbeats[pubkey]) {
success(res, 'success')
clearInterval(interval)
delete heartbeats[pubkey]
return
}
i ++
i++
}, 1000)
}

11
src/utils/res.ts

@ -16,4 +16,13 @@ function failure(res, e) {
res.end();
}
export {success, failure}
function failure200(res, e) {
res.status(200);
res.json({
success: false,
error: (e&&e.message) || e,
});
res.end();
}
export {success, failure, failure200}
Loading…
Cancel
Save