Thursday, 2 November 2017

Pattern for cancelling long, complex function

I'm working to refactor a rather intricate piece of code we have with something that is easier to grok. So the gist of the problem is that we run validation when a user uploads a file. Each file contains many records (each line is a record) and when validating a record the database is hit (to check for existence in another collection).When another file is uploaded we cancel the validation in process and start over again (as the data has changed). We use a setInterval to check if the list of uploaded files has changed. The whole process is asynchronous so it doesn't starve the event loop.This all works but like I said, is very hard to follow. I was wondering if there was some sort of pattern that would be better suited for this sort of problem. I was looking into child_process (especially fork) but it seems like this would not scale at all. A message queue is not a viable solution either. Any ideas?

Submitted November 03, 2017 at 03:23AM by somethingrandom222

No comments:

Post a Comment