bitcointranscripts / transcription-review-backend

7 stars 11 forks source link

fix: refactor credit transaction process in webhook controller #262

Closed Extheoisah closed 9 months ago

Extheoisah commented 9 months ago

This pr fixes the timeout issue when a review pr is merged in the btc transcript repo. Sometimes, the content diff is too large that the function to create the credit transaction takes longer than usual to resolve. And due to Javascript single threaded nature, it blocks the main server from processing incoming requests asynchronously until the expensive function is resolved. This commit proposes a hot fix (a much better should follow) which utilises NodeJs thread workers and Redis queueing system to asynchronously allocate memory on another thread separate from the main server thread to run the credit transaction process. This approach ensures the webhook response is almost instant while the transaction process is queued in the redis cache and once each transaction job is resolved, it clears from the queue and moves on to the other job.

For errors that might occur during this process, the sendAlert function has been modified to accomodate transaction alerts sents to the discord bot. Only failed transaction alerts are notified as there is currently no reason to implement successful alert notification except on the user side (i.e. to user emails- should be in another pr)