I looks like these 3 lines also exist in `handle_job_events()` could you extract it into a function and call it in both places.