Poll on the endpoint for 120 secs after zap request then it will handoff to long running invoices cron

This commit is contained in:
austinkelsay 2024-11-08 10:55:01 -06:00
parent 91e098f68d
commit 6e415ce7f2
No known key found for this signature in database
GPG Key ID: 44CB4EC6D9F2FA02

View File

@ -76,6 +76,28 @@ export default async function handler(req, res) {
settled: false settled: false
}, { ex: expiry || 86400 }); // expiry matches invoice expiry }, { ex: expiry || 86400 }); // expiry matches invoice expiry
// Start polling for this zap request
let attempts = 0;
const pollInterval = setInterval(async () => {
try {
const pollResponse = await axios.get(`${BACKEND_URL}/api/invoices/polling`, {
headers: {
'Authorization': PLEBDEVS_API_KEY
}
});
// If no pending invoices or we've reached max attempts, stop polling
if (pollResponse.data.pending === 0 || attempts >= 120) {
clearInterval(pollInterval);
}
attempts++;
} catch (error) {
console.error('Polling error:', error);
clearInterval(pollInterval);
}
}, 1000); // Poll every second
res.status(200).json({ res.status(200).json({
invoice, invoice,
payment_hash: paymentHashHex, payment_hash: paymentHashHex,