mirror of
https://github.com/AustinKelsay/plebdevs.git
synced 2025-06-06 09:12:05 +00:00
Poll on the endpoint for 120 secs after zap request then it will handoff to long running invoices cron
This commit is contained in:
parent
91e098f68d
commit
6e415ce7f2
@ -76,6 +76,28 @@ export default async function handler(req, res) {
|
||||
settled: false
|
||||
}, { 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({
|
||||
invoice,
|
||||
payment_hash: paymentHashHex,
|
||||
|
Loading…
x
Reference in New Issue
Block a user