Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know when delayed_job has done its job?

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 scraping 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.

like image 739
Teej Avatar asked Oct 25 '22 03:10

Teej


1 Answers

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.

like image 158
jaydel Avatar answered Oct 27 '22 09:10

jaydel