开发者

How to know when delayed_job has done its job?

开发者 https://www.devze.com 2023-03-27 22:47 出处:网络
I currently have a method in my model to scrape a site and insert records to a database. def self.scrape

I currently have a method in my model to scrape a site and insert records to a database.

def self.scrape
  #scrape
  #insert into database
end

I set up a controller method to call it:

def scrape
  Website.send_later(:scrape)
end

The s开发者_高级运维craping is working and have tested it by running it through the console. However, running it by activating it through calling the controller method it didn't work.

I've tried rake jobs:work it says the following:

[Worker(host:thorpe-desktop pid:6962)] Starting job worker
[Worker(host:thorpe-desktop pid:6962)] Class#scrape completed after 0.5068
[Worker(host:thorpe-desktop pid:6962)] 1 jobs processed at 0.5898 j/s, 0 failed ...

I don't see anything in the database table where it should have inserted data.


As a way to figure out if a job has run and completed you can use the hooks provided by delayed_job to write a small record to a job_status model. there are a few hooks that might be useful in this case and most interesting is:

def after(job)
  record_stat 'newsletter_job/after'
end

There are similar ones for success and finish that you could use similarly. I realize this might be heavier than you desire but it would do what you want and may be worth the cost. The delayed_job table doesn't seem to hold enough information as is for what you want.


This question polling with delayed_job has a good description of how to track when delayed jobs have finished or not.

0

精彩评论

暂无评论...
验证码 换一张
取 消