ruby on rails - Writing a DelayedJob custom job to run script and then destroy object -
i've been trying figure out long time, , can't figure out.
i using delayedjob in rails app in order run script fill out forms on website via mechanize script. however, after job completes, don't want record of entry stored in database in application, there no reason should access again.
the process works when ran simple background method within controller's create
method - is, calling @course.delay.scrape
right after if @course.save
. want destroy object right after background job finishes, believe need create custom job, , struggling that.
i aware delayedjob documentation lists method def after(job)
. in order use method, need create custom job. i'm confused how create custom job, every example can find sending mass emails, whereas different purpose. don't know how script run way.
if can me fixing code @ all, appreciated! i've tried many variations, looking @ many examples possible. i'm aware has @ least few errors, not advanced enough know change. last thing tried before throwing in towel.
here model (in models/course.rb):
class course < activerecord::base after_create :send_to_delayed_job def scrape ...mechanize script goes here .... end def send_to_delayed_job delayed::job.enqueue coursejob.new(self.id), :queue => 'mycoursequeue' end end
here job (in models/course_job.rb):
class coursejob < struct.new(:course_id) def perform course = course.find(self.id) course.scrape end def after(job) course.destroy(params[:id]) end end
can have course.destroy
last line of coursejob#perform
method?
Comments
Post a Comment