delayed_job
delayed_job copied to clipboard
Job not being enqueued when using perform_later from ActiveJob
I'm using DelayedJob through the ActiveJob library.
At a certain moment, I call the perform_later
method (form ActiveJob) to enqueue a task. It works fine in the app and all the tests are ok when I run model tests (I'm using RSpec).
The problem occurs when I run mailer specs. The same line of code is not enqueuing the job when it is run by the mailer specs. I've realized where was the problem by using the around_enqueue callback as below.
class CreateAsyncWalletEntryJob < ApplicationJob
queue_as :default
around_enqueue :just_debugging
def perform wallet_entry_data
WalletEntry.create!(wallet_entry_data)
end
private
def just_debugging
jobs_before = Delayed::Job.all.count
yield
jobs_after = Delayed::Job.all.count
# when it runs through mailer specs: jobs_before == jobs_after
# otherwise: jobs_before + 1 == jobs_after
end
end
The code below is the moment I call the enqueue method
CreateAsyncWalletEntryJob.perform_later(payment_data)
I am already setting Delayed Jobs to enqueue tasks while running the tests, but it is not taking effect with my mailer specs.
Delayed::Worker.delay_jobs = true
I have already checked if the perform
method is running, but it isn't, which means that the problem is not related to instant execution instead of enqueuing. It is not adding to the queue and not running the perform method at all! And there is no error, it's totally silent.
Any ideas?
did you found any solution? am trying to test something similar
Just stumbled on this. It is happening in my case also. Anyone found more about it?
Found something
MyJob.queue_adapter.enqueued_jobs
You can then get the enqueued_jobs
Closing stale