Closed jdantonio closed 8 years ago
This update moves more functionality into the Queue
class. A Queue
is now a full Concurrent::Executor
service with the associated lifecycle methods. Most of the attribute methods are simply delegated to the underlying ThreadPoolExecutor
using Ruby's Forwardable
module. The remaining methods are implemented according to Sucker Punch's specific needs.
The "soft" shutdown is now handled by the Job
class. When it sees that the application is shutting down it ignores any remaining jobs. The thread pool will still try to execute every job in its queue, but the aforementioned short-circuit renders all enqueued jobs effectively noop.
Finally, the default shutdown handler posts a final "tracking" job to every queue on shutdown. This job simply counts do a Concurrent::CountDownLatch
given to it by the handler. Because the thread pool still runs every job in queue, these tracking jobs still get run. Because these jobs get post directly to the pool, they skip the shirt-circuit of Job
. This allows the shutdown handler to wait on all queues with one aggregate timeout rather than iterating over each and calling wait_for_termination
.
This is great stuff. Should've thought to use Concurrent::CountDownLatch
in the shutdown. It's been a great tool for testing. Thanks so much for the contribution. I'm really excited about getting a beta out there!
Nice work here!
Better shutdown handling. See #144, #146, and #147.