How do I know when delayed_job did its job?

Currently, I have a method in my model to clean the site and insert records into the database.

def self.scrape #scrape #insert into database end 

I set the controller method to call it:

 def scrape Website.send_later(:scrape) end 

The scraper works and tested it by running it through the console. However, by launching it, activating it, calling the controller method, it did not work.

I 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 see nothing in the database table where it should have inserted data.

+4
source share
2 answers

As a way to find out if the job has been completed and completed, you can use the hooks provided by delayed_job to write a small record to the job_status model. There are several hooks that can be useful in this case, and the most interesting is:

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

There are similar ones for success and completion that you could use in a similar way. I understand that it may be harder than you want, but it will do what you want and it may be worth it. The delayed_job table does not seem to contain enough information, just like for what you want.

+2
source

This question poll with a delay_job contains a good description of how to track the completion of tasks with a delay or not.

+1
source

All Articles