Ugly hack for Starling – Workling in Rails

Posted in rails by elisehuard on November 4, 2008

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).
# Wait for all workers to complete
@workers.list.each { |t| t.join }

with preload_classes declaring any classes you might need:
def preload_classes

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

Tagged with: , , ,

2 Responses

Subscribe to comments with RSS.

  1. rany said, on November 11, 2008 at 3:05 pm

    hey there,

    i’m aware of this issue, but i’m somewhat reluctant to add this kind of loading code to workling, for the following reason.

    passing complete ar objects across the wire is something i tend to discourage. i even plan to add a linting runner for the test environment that warns you when you pass active record objects to worker methods. it’s better to pass ids across and then grab the model from the database at the other end.

    this issue is not unlike rails sessions. if you place ar objects in the session, you have to explicitly declare this, or you’ll get the same kind of error you’re seeing here. doing this is discouraged in most documentation though.

    so i think if a linting runner is added, it will at least remove confusion about what’s happening.

  2. elisehuard said, on November 11, 2008 at 3:10 pm

    This makes sense. I’ll make a follow-up (correction) post if i can make your suggestion work.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: