-
Notifications
You must be signed in to change notification settings - Fork 22k
Description
Steps to reproduce
(sorry, only happens with Rails console, so couldn't create a script)
Create a job:
class TestJob < ApplicationJob
def perform
puts "Job enqueued for #{Time.now - Time.parse(enqueued_at)} seconds"
end
endCreate a user that runs the job in a callback:
class User < ApplicationRecord
before_save :run_job
def run_job
TestJob.perform_later
end
endRun rails console and before running any other jobs, run:
User.create!Expected behavior
The job should run immediately, like it does if you run:
TestJob.perform_lateror
TestJob.perform_later; User.create!Actual behavior
If you use a Postgres database, the job will hang indefinitely (until you press control + c twice on Mac). If you use SQLite, the job will be delayed for 10 seconds. This only happens with the default async adapter, not the inline adapter. Jobs seem to hang at other points as well (was originally going to post on A May of WTFs), but can only reliably reproduce if it's the first job run.
Enqueued TestJob (Job ID: 876b2347-0280-4e80-8309-eef3f1e08a4a) to Async(default)
Performing TestJob (Job ID: 876b2347-0280-4e80-8309-eef3f1e08a4a) from Async(default) enqueued at 2020-05-25T23:59:39Z
Job enqueued for 10.330646 seconds
Performed TestJob (Job ID: 876b2347-0280-4e80-8309-eef3f1e08a4a) from Async(default) in 5.41ms
If you use after_save or after_commit (like ActiveStorage::PurgeJob and ActiveStorage::AnalyzeJob), jobs are delayed for 10 seconds as well.
This seems like a weird one, so I'm not sure if it's just my machine or others are seeing this as well.
System configuration
Rails version: 6.0.3.1
Ruby version: 2.7.1