dont process all previous requests on boot

This commit is contained in:
zramsay 2025-06-26 11:16:55 -04:00
parent fa4628a153
commit 84fd528619

View File

@ -26,9 +26,12 @@ class PaymentProcessor {
private regHelper: RegHelper;
private processedHashes: Set<string> = new Set();
private checkInterval: number = 30000; // 30 seconds
private lastProcessedTime: Date = new Date();
constructor() {
this.regHelper = new RegHelper();
// Only process requests from the last 10 minutes on startup
this.lastProcessedTime = new Date(Date.now() - 10 * 60 * 1000);
}
/**
@ -55,20 +58,30 @@ class PaymentProcessor {
}
/**
* Process new ApplicationDeploymentRequest records
* Process new ApplicationDeploymentRequest records (only recent ones)
*/
private async processNewRequests(): Promise<void> {
try {
// Query for all ApplicationDeploymentRequest records
const requests = await this.regHelper.queryRecords({
const allRequests = await this.regHelper.queryRecords({
type: 'ApplicationDeploymentRequest',
});
console.log(`Found ${requests.length} deployment requests`);
// Filter to only process recent requests (created after lastProcessedTime)
const recentRequests = allRequests.filter(request => {
const createTime = new Date(request.createTime);
return createTime > this.lastProcessedTime;
});
for (const request of requests) {
console.log(`Found ${allRequests.length} total deployment requests, processing ${recentRequests.length} recent ones`);
for (const request of recentRequests) {
await this.processRequest(request);
}
// Update lastProcessedTime to now
this.lastProcessedTime = new Date();
} catch (error) {
console.error('Error querying deployment requests:', error);
}
@ -91,6 +104,18 @@ class PaymentProcessor {
return;
}
// Skip if request already has a deployment (already successfully processed)
const existingDeployments = await this.regHelper.queryRecords({
type: 'ApplicationDeploymentRecord',
request: requestId
});
if (existingDeployments.length > 0) {
console.log(`Skipping request ${requestId} - already has deployment`);
this.processedHashes.add(paymentHash);
return;
}
console.log(`Processing request ${requestId} with payment hash ${paymentHash}`);
try {