[Backgroundrb-devel] trouble using ActiveRecord classes
Mason Hale
masonhale at gmail.com
Fri Dec 8 18:31:49 EST 2006
I've been trying unsuccessfully for the better part of today to write a
worker that can use by ActiveRecord model classes.
The bizarre thing is that worker just stops at the point accessing the
database connection. An exception isn't raising, it just dies.
My worker class is below, I've interspersed log messages throughout to try
to determine where it is dying.
===== publish_worker.rb ========
require 'publication' # loads my Publication < ActiveRecord::Base model
class PublishWorker < BackgrounDRb::Worker::RailsBase
attr_accessor :publication_id
def do_work(args)
logger.debug("PublishWorker args: #{args.inspect}")
@publication_id = args[:publication_id]
logger.debug("Publication id: #{@publication_id}")
end_date = args[:end_date] || Time.now.utc
logger.debug("End date: #{end_date}")
begin
logger.debug("In begin block")
logger.debug("Publication.table_name: #{Publication.table_name}")
logger.debug("Publication.connected?: #{Publication.connected?}")
logger.debug("Publication.connection: #{Publication.connection.inspect
}")
logger.debug("Publication.count: #{Publication.count}")
rescue
logger.debug("Got error: #{$!}")
end
pub = Publication.find(@publication_id)
pub.publish_for_date(end_date)
end
end
PublishWorker.register
=============================
In the log/backgroundrb.log file I see:
20061208-17:23:38 (3611) Starting WorkerLogger
20061208-17:23:38 (3612) In ResultsWorker
20061208-17:23:54 (3612) PublishWorker args: {:publication_id=>"1"}
20061208-17:23:54 (3612) Publication id: 1
20061208-17:23:54 (3612) End date: Fri Dec 08 23:23:54 UTC 2006
20061208-17:23:54 (3612) In begin block
20061208-17:23:54 (3612) Publication.table_name: publication
20061208-17:23:54 (3612) Publication.connected?: false
Which means it never logged the "Publication.connection.inspect" message,
and also did not log an error.
It's weird that I can get access to my model class but can't access the db
connection.
By the way, I'm working with a PostgreSQL database and its associated
adapter.
Any suggestions or pointers on where to look to track down the issue are
greatly
appreciated.
thanks in advance,
Mason
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/backgroundrb-devel/attachments/20061208/2e2f249c/attachment.html
More information about the Backgroundrb-devel
mailing list