delayed_job icon indicating copy to clipboard operation
delayed_job copied to clipboard

Job not being enqueued when using perform_later from ActiveJob

Open LeoGardel opened this issue 6 years ago • 3 comments

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?

LeoGardel avatar Oct 19 '18 00:10 LeoGardel

did you found any solution? am trying to test something similar

pablosky avatar Aug 20 '19 04:08 pablosky

Just stumbled on this. It is happening in my case also. Anyone found more about it?

thebravoman avatar Nov 23 '20 19:11 thebravoman

Found something

MyJob.queue_adapter.enqueued_jobs

You can then get the enqueued_jobs

thebravoman avatar Nov 23 '20 19:11 thebravoman

Closing stale

albus522 avatar Jul 26 '24 19:07 albus522