Copied these bits from delayed_job