简体   繁体   中英

DelayedJob gem behaving different in local and on heroku

I am a newbie to delayed job but in local the gem is working flawlessly. In production, the gem logs an entry in delayed_jobs table and then within milli-seconds completes it, deletes it without processing.

A critical difference I found was the handler entry created in the database.

Local

--- !ruby/object:Delayed::PerformableMethod
object: !ruby/ActiveRecord:User
 attributes:
 id: '1'
 email: abc@example.com.au
 is_pending: pending
method_name: :job_without_delay
args:
- false

Heroku

--- !ruby/object:Delayed::PerformableMethod
attributes:
 id: 1
 email: abc@example.com.au
 is_pending: pending

What is going on? Can any one please assist?

Controller

def make_pending
@user = current_user
@user.job(false)
redirect_to user_path(current_user)
end

User Model

def job(silence)
Project.job(self.id, silence)
end
handle_asynchronously :job, :run_at => Proc.new { 5.minutes.from_now }

Another difference

Local logs

[Worker(host:__.local pid:5179)] Starting job worker
[Worker(host:__.local pid:5179)] User#job_without_delay completed after 417.0975
[Worker(host:__.local pid:5179)] 1 jobs processed at 0.0024 j/s, 0 failed ...

Heroku logs

013-01-14T12:15:37+00:00 app[worker.1]: [Worker(host:19edbbfb-b8b9-4528-bca6-46ecac4e66bc pid:2)] NilClass# completed after 0.0119
2013-01-14T12:15:37+00:00 app[worker.1]: [Worker(host:19edbbfb-b8b9-4528-bca6-46ecac4e66bc pid:2)] 1 jobs processed at 26.9897 j/s, 0 failed ...

Finally found solution

Added a new model dj.rb

class Dj < Struct.new(:uid, :silence)

  def perform
......
  end
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM