user2644040
user2644040

Reputation: 115

Rails delayed_job stuck on runnin

I am trying to use a very basic delayed job on rails:

class ImportJob < Struct.new(:job_params)


    def perform
        #blank perform
    end
end

And When I queue that job all I see in rake:jobs is that the job is RUNNING, but it never finishes:

Delayed::Job.enqueue ImportJob.new(job_params)

Furthermore if I run the job worker from the rails console I see the job get 'locked' and then immediately deleted:

2.1.2 :001 > work = Delayed::Worker.new
=> #<Delayed::Worker:0x007f8a8c4d2ee8 @quiet=true, @failed_reserve_count=0> 
2.1.2 :002 > work.start
Delayed::Backend::ActiveRecord::Job Load (1.8ms)  SELECT "delayed_jobs".* FROM "delayed_jobs" WHERE ((run_at <= '2014-07-16 19:10:54.367527' AND (locked_at IS NULL OR locked_at < '2014-07-16 15:10:54.367862') OR locked_by = 'host:jerrods-mbp.raleigh.ibm.com pid:36564') AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT 5
Delayed::Backend::ActiveRecord::Job Load (3.5ms)  SELECT "delayed_jobs".* FROM "delayed_jobs" WHERE ((run_at <= '2014-07-16 19:10:59.386290' AND (locked_at IS NULL OR locked_at < '2014-07-16 15:10:59.386563') OR locked_by = 'host:jerrods-mbp.raleigh.ibm.com pid:36564') AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT 5
SQL (5.9ms)  UPDATE "delayed_jobs" SET "locked_at" = '2014-07-16 19:10:59.387743', "locked_by" = 'host:jerrods-mbp.raleigh.ibm.com pid:36564' WHERE "delayed_jobs"."id" IN (SELECT "delayed_jobs"."id" FROM "delayed_jobs" WHERE "delayed_jobs"."id" = 6 AND ((run_at <= '2014-07-16 19:10:59.386290' AND (locked_at IS NULL OR locked_at < '2014-07-16 15:10:59.386563') OR locked_by = 'host:jerrods-mbp.raleigh.ibm.com pid:36564') AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC)
Delayed::Backend::ActiveRecord::Job Load (0.7ms)  SELECT "delayed_jobs".* FROM "delayed_jobs" WHERE "delayed_jobs"."id" = ? LIMIT 1  [["id", 6]]
(0.1ms)  begin transaction
SQL (0.5ms)  DELETE FROM "delayed_jobs" WHERE "delayed_jobs"."id" = ?  [["id", 6]]
(2.6ms)  commit transaction

Has anyone ever seen this behavior before?

Upvotes: 2

Views: 1277

Answers (2)

user2644040
user2644040

Reputation: 115

Alright so after reading various other threads on here and other places I came by the following solution:

  1. I realized it was failing silently for whatever reason so I added Delayed::Worker.destroy_failed_jobs = false config/application.rb

  2. With that line added I was able to go in the console and get Delayed::Job.last.last_error and it told me that my job file wasn't being loaded in rake for whatever reason

  3. To solve this I created a custom.rb in initlializers and added the following line: require 'my_class'

Hopefully this will help someone else

Upvotes: 4

pdobb
pdobb

Reputation: 18037

I don't see anything out of the ordinary here. When a job completes successfully it is deleted from the delayed_jobs queue / database table. You could have your job raise an error and see what happens when one doesn't complete successfully:

def perform
   raise "BOOM, goes the dynamite!"
end

It should be outputting a count of jobs completed successfully in any given "run period", however. See the source here for that.

Upvotes: 0

Related Questions