Jabberwocky

snicker-snack!

Ugly Hack for Starling - Workling in Rails

| Comments

Update: this hack is not necessary. As pointed out by Rany in the comments, when you pass the object ids instead of the objects themselves, the error doesn’t occur. Then retrieve them when necessary in the worker.

I started using Workling – Starling in my current project, having had my fill of backgroundrb in last project. Problem: when i actually scheduled a job, i got following error:

/Library/Ruby/Gems/1.8/gems/memcache-client-1.5.0/lib/memcache.rb:214:in `load': undefined class/module Xxxxyyy (ArgumentError)

This looks like a bug, and the alarming thing is that I’ve seen it reported as far as one year back. I got my solution looking at following post.

To get this working, you need to declare the ActiveRecord classes required for your worker into vendor/plugins/workling/lib/workling/remote/invokers/threaded_poller.rb (where the workers are actually placed in the Starling queue).

1
2
3
# Wait for all workers to complete
preload_classes
@workers.list.each { |t| t.join }

with preload_classes declaring any classes you might need:

1
2
3
4
5
def preload_classes
  User
  Model1
  Model2
end

As the project progresses, it might be neater to put the preload_classes in the loop, so that you only load the classes needed for one particular type of worker. It works, anyhow

Comments