Fix threading issue with delayed job