I've updated the before_fork and after_fork callbacks. Here's the nuts and bolts:
before_fork is called by DelayedJob only on the parent process, which doesn't ever execute jobs. Since this doesn't need to talk to the DB, we should ensure it's Mongoid connections are closed.
after_fork is called on child processes as they are forked from the parent. I've updated the logic to obtain fresh connections. Technically speaking this is not necessary as a Mongoid 5+, because the Mongo Ruby Driver checks if pid to see if it has been forked. However, since we know we are forking it's good practice to do this immediately rather than waiting for Mongo Driver to do it.
In addition, this PR make some Job class method private which should not be exposed publicly.
I've added specs to increase coverage. I've also removed the YARDstick gem which verifies documentation. Bye-bye.
Coverage decreased (-24.1%) to 64.474% when pulling 49802efca14002b6e45580b8291d36df862bbced on johnnyshields:forking-improvements into db87465e649a18209bf9cd21a56a765bf7c584c4 on collectiveidea:master.
Coverage increased (+2.2%) to 90.789% when pulling c4f10f6bc3022bcdb02e8153bb93d7e09ab258da on johnnyshields:forking-improvements into db87465e649a18209bf9cd21a56a765bf7c584c4 on collectiveidea:master.
This is a follow-up to #81.
I've updated the
before_fork
andafter_fork
callbacks. Here's the nuts and bolts:before_fork
is called by DelayedJob only on the parent process, which doesn't ever execute jobs. Since this doesn't need to talk to the DB, we should ensure it's Mongoid connections are closed.after_fork
is called on child processes as they are forked from the parent. I've updated the logic to obtain fresh connections. Technically speaking this is not necessary as a Mongoid 5+, because the Mongo Ruby Driver checks if pid to see if it has been forked. However, since we know we are forking it's good practice to do this immediately rather than waiting for Mongo Driver to do it.In addition, this PR make some Job class method private which should not be exposed publicly.
I've added specs to increase coverage. I've also removed the YARDstick gem which verifies documentation. Bye-bye.