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
Following up on my previous post: I tracked this problem down to an issue with the way native code libraries are loaded by Ruby on Mac OS. This affected the rails script/console in the past, and still apparently affects DRb. The underlying issue is at a lower layer than BackgrounDRb and so it not related to BackgrounDRb after all. More info about this particular issue can be found here: http://dev.rubyonrails.org/ticket/1283 My workaround is to use the ''pure-ruby'' postgres driver on Mac OS X. The native driver still works on other platforms. Long-term fix is to patch DRb (similar to the wa IRB was patched to fix the above issue), or wait on Apple to fix the apparent bug in their .bundle loading routines. best regards, Mason On 12/8/06, Mason Hale <masonhale at gmail.com> wrote:> > 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/20061214/f85526fe/attachment.html
Ezra Zygmuntowicz
2006-Dec-14 19:41 UTC
[Backgroundrb-devel] trouble using ActiveRecord classes
Mason- Thank you for following up on this. Interesting problem I haven''t seen that one before. Cheers- -Ezra On Dec 14, 2006, at 9:51 AM, Mason Hale wrote:> Following up on my previous post: I tracked this problem down to an > issue with the way native code libraries are loaded by Ruby on Mac OS. > > This affected the rails script/console in the past, and still > apparently affects DRb. The underlying issue is at a lower > layer than BackgrounDRb and so it not related to BackgrounDRb after > all. > > More info about this particular issue can be found here: > http://dev.rubyonrails.org/ticket/1283 > > My workaround is to use the ''pure-ruby'' postgres driver on Mac OS > X. The native driver still works on other platforms. > Long-term fix is to patch DRb (similar to the wa IRB was patched to > fix the above issue), or wait on Apple to fix the apparent bug in > their .bundle loading routines. > > best regards, > > Mason > > > On 12/8/06, Mason Hale <masonhale at gmail.com> wrote: 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 > > > _______________________________________________ > Backgroundrb-devel mailing list > Backgroundrb-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/backgroundrb-devel-- Ezra Zygmuntowicz -- Lead Rails Evangelist -- ez at engineyard.com -- Engine Yard, Serious Rails Hosting -- (866) 518-YARD (9273)