Factor out the worker failure handler.

Need to use it elsewhere too.