Refactor handle_worker_exit