[Backgroundrb-devel] Scheduled workers only run once unless you call self.delete inside the worker

David Balatero david.balatero at gmail.com
Mon Mar 5 17:24:37 EST 2007

I had a worker scheduled to run every minute with

  :class: :ebay_auction_worker
  :job_key: :ebay_auction_runner
  :trigger_type: :cron_trigger
  :trigger_args: 0 * * * * * *

This worker posts an auction to eBay from a queue of auctions every minute.
I was having a problem where the worker would run ok the first time, but
never any subsequent minutes after that. The way I fixed it was adding a
call to self.delete at the end of every do_work() method:

class EbayAuctionWorker < BackgrounDRb::Rails
  # Set this worker to run every minute.
  attr_accessor :progress, :description

  def do_work(args)
    # This method is called in it's own new thread when you
    # call new worker. args is set to :args

    @progress = 0
    @description = "Checking for eBay auctions and posting"

    logger.info("Checking to post an auction at #{Time.now.to_s}.")
    auction = EbayAuction.find(:first, :conditions => ["auction_status = ?
AND post_on < ?", EbayAuction::STATUS_STRINGS[:queued], Time.now])
    if auction
      logger.info("--- Posting auction: #{auction.title}")

      logger.info("--- No auctions currently need posting.")

    @progress = 100

    logger.info("--- Finished auction check.")

    # Exit the thread, see what happens


Does this make sense? I never saw any mention of having to do this with
scheduled workers in the documentation. Shouldn't the scheduler
automatically clean up the worker with a self.delete, after @progress is >=

David Balatero
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/backgroundrb-devel/attachments/20070305/f8254fca/attachment.html 

More information about the Backgroundrb-devel mailing list