chell
chell

Reputation: 7866

How can I use delayed job in a call back function in Rails

I'm using delayed_job gem.

I want to call a method using a callback as follows

after_update :get_score

How can I use delay_job for this so that the get_score method is run in the background?

Upvotes: 1

Views: 753

Answers (2)

rilla
rilla

Reputation: 638

How about this? Works for me.

after_update :get_score

private
def get_score
  # code
end
handle_asynchronously :get_score

Upvotes: 3

axsuul
axsuul

Reputation: 7480

I'm not too familiar with delayed_job, but judging from its docs, this should work.

after_update :obtain_score

def get_score
   # code
end

private
def obtain_score
  delay.get_score
end

Upvotes: 0

Related Questions