-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Jobs are all paused; improve module loading issue #34
Comments
Got error
|
Sandbox process caveatA big, perhaps even surprising insight is that sandbox process will create a completely separate process from the master one, thus not sharing any object, references w/ the master process, unless using nodejs process messaging (which Bull is doing under the hood to achieve some functionalities). Thus this Bull issue thread suggest that we re-create the queue instance in sandbox process -- even if we already create the queue in master process. To conclude, the timing to do such re-create in sandbox process is when we need to either access a queue event or dispatch job of a queue in sandbox process, we will need to re-construct that queue instance. Some questions immediately emerges -- if we are re-creating queue instance, will that duplicate redis clients and create unnecessary redis connections, even if in concept the number of unique queues is fixed. We sum up the questions here:
Looks like re-creating queues in sandbox process is the way to go. Of course, only re-create those queues that are used in that sandbox processor, other queues you don't need to re-create them. |
Solved by initializing queues also in sandbox. But this should be done in a minimum - only if that sandbox process really needs that queue. |
We observed some code are run multiple times when starting the server, but wasn't able to figure out why, even for objects that intentionally written as a singleton, the duplicate loading issue still happens. This also potentially leads to
npm test
not able to terminate w/o--exit
intervention.Luckily, we saw this SO post about singleton, but also mentions avoiding module being loaded multiple time. The answer refers to a nodejs document, where it states that a mixture of commonJs and ES module import will cause issues and breaks the "module caching".
Indeed, when we look at several
process.ts
file, we surprisingly found we still haveconst Bull = requires('bull')
. This could really be the issue described in the document.After fixing the issue, we should test locally, and at the end, in production, that indeed it's not duplicating module loading - by either printing
console.log
and verify only single lines are printed.Then, we should deal with the job pause problem. Looks like previously when shutdown, the
.pause()
makes the job queue in redis marked as paused, and this states carries over to the new express server. I guess there's some persistency Bull built-in using redis key-value store to achieve such state persistency. So the new server now begins with all queues in paused state.How to deal with the paused queues issue? The simplest, cleanest way, is to flushdb - this shall clear all the state -- but will clean all the job history as well. But since we've finished looking at previously failed s3 org job & no further action to take, those job history is not necessary. Other approach will be to deploy a server with a
.resume()
clause instartJobQueue()
initializer, but then we'll need to wait for hours for all jobs to finish. It's really a pain in the ass that we cannot abort the jobs. But I guess we can destroy the container -- either through cli or the kubernetes dashboard.Conclusion
.pause()
. And in dev we're already flushing db so shouldn't matter much.--exit
, runnpm test
, see if there's any duplicated console log, see if it can gracefully terminated.initializer
that willnew
the queue. If that initializer func is not called, no queue is newed. This should be able to avoid necessary job queues that has to be finalized and closed, and redis connections.npm test
can be terminated gracefully without--exit
, get ready for production. Flush production db.rrr
, just use a small amount review org. If everything looks good, do accc
.The text was updated successfully, but these errors were encountered: