diff --git a/src/paymentProcessor.ts b/src/paymentProcessor.ts index eeb6160..53085ba 100644 --- a/src/paymentProcessor.ts +++ b/src/paymentProcessor.ts @@ -26,9 +26,12 @@ class PaymentProcessor { private regHelper: RegHelper; private processedHashes: Set = 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 { 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 {