We have been happily using cache-money here for a while and today I decided
to try to get backgroundrb going as well.  Unfortunately they don't play
well together.  Here's the situation and the hack-solution I put in place...

Cache Money depends on an initializer that sets some variables and loads the
gem.  One thing that it does is override ActiveRecord::Base transaction

>From the Cache Money Source:
----------------
  module ClassMethods
    def self.extended(active_record_class)
      class << active_record_class
        alias_method_chain :transaction, :cache_transaction
      end
    end

    def transaction_with_cache_transaction(&block)
      repository.transaction { transaction_without_cache_transaction(&block)
}
    end
  end
----------------

Ok, so where does that "repository" variable get set?  You create an
initializer to install cache_money (per their instructions)


----------------
require 'cache_money'

config = YAML.load(IO.read(File.join(RAILS_ROOT, "config",
"memcached.yml")))[RAILS_ENV]
$memcache = MemCache.new(config)
$memcache.servers = config['servers']

$local = Cash::Local.new($memcache)
$lock =  Cash::Lock.new($memcache)
$cache = Cash::Transactional.new($local, $lock)

class ActiveRecord::Base
  is_cached :repository => $cache
end
----------------

Ok, so great.  I got backgroundrb all setup and i'm about to write some
great workers but.. oh no!  the daemon barfs because it doesn't have the
proper cache setup!


---------------
stephen-blackstones-power-mac-g5:freedom4 sblackstone$ (__DELEGATION__):2:in
`__send__': You have a nil object when you didn't expect it! (NoMethodError)
The error occurred while evaluating nil.repository    from
(__DELEGATION__):2:in `repository'
    from
/Library/Ruby/Gems/1.8/gems/nkallen-cache-money-0.2.5/lib/cache_money.rb:50:in
`transaction'
    from
/Users/sblackstone/development/freedom4/vendor/plugins/backgroundrb/lib/backgroundrb/bdrb_job_queue.rb:9:in
`find_next'
    from
/Users/sblackstone/development/freedom4/vendor/plugins/backgroundrb/server/lib/meta_worker.rb:356:in
`get_next_task'
    from
/Users/sblackstone/development/freedom4/vendor/plugins/backgroundrb/server/lib/meta_worker.rb:336:in
`check_for_enqueued_tasks'
    from
/Users/sblackstone/development/freedom4/vendor/plugins/backgroundrb/server/lib/meta_worker.rb:130:in
`worker_init'
    from
/Library/Ruby/Gems/1.8/gems/packet-0.1.15/bin/../lib/packet/packet_periodic_event.rb:23:in
`call'
    from
/Library/Ruby/Gems/1.8/gems/packet-0.1.15/bin/../lib/packet/packet_periodic_event.rb:23:in
`run'
     ... 10 levels...
    from
/Library/Ruby/Gems/1.8/gems/packet-0.1.15/bin/packet_worker_runner:47:in
`new'
    from
/Library/Ruby/Gems/1.8/gems/packet-0.1.15/bin/packet_worker_runner:47
    from /usr/bin/packet_worker_runner:19:in `load'
    from /usr/bin/packet_worker_runner:19
***** LOADING CACHE MONEY CONFIG
---------------


Ok, well for now lets just make the job queue use the non-cached version
until someone on the development list can point me to the best solution to
this! =)


stephen-blackstones-power-mac-g5:freedom4 sblackstone$ svn diff
vendor/plugins/backgroundrb/lib/backgroundrb/bdrb_job_queue.rb
Index: vendor/plugins/backgroundrb/lib/backgroundrb/bdrb_job_queue.rb
===================================================================
--- vendor/plugins/backgroundrb/lib/backgroundrb/bdrb_job_queue.rb
(revision 5847)
+++ vendor/plugins/backgroundrb/lib/backgroundrb/bdrb_job_queue.rb
(working copy)
@@ -6,7 +6,7 @@
   def self.find_next(worker_name,worker_key = nil)
     returned_job = nil
     ActiveRecord::Base.verify_active_connections!
-    transaction do
+    transaction_without_cache_transaction do




Thanks!
Stephen Blackstone
_______________________________________________
Backgroundrb-devel mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/backgroundrb-devel

Reply via email to