I’m building a Node server that serves large files for download and streaming. It will be necessary to modify these files on occasion, sometimes in bulk with a script. I want to be able to update them without interrupting downloads in progress.
What I’ve come up with is a system where for a given file’s database entry, I’ll have an “in use” flag, and an “updating” flag. I’ll need to set the “in use” flag to true when a download begins, and somehow emit an event that sets the flag to false whenever the last download completes.
The “updating” flag will prevent any further downloads. When I initiate a script to update the files, it will first change a given file’s “updating” flag to true, then check the “in use” flag. If it is true, it will register a listener for the last download complete event mentioned above, which will update the file.
My question is, is this completely crazy? Is there a common pattern for this problem?
12