mperham/girl_friday — Issue #48: Setting up girl_friday in sinatra app
Author: ckbhodge
Created: 2012-02-28 00:20:06+00:00
State: open

I'm a newbie so I'm sorry if this question is off-base.

I have an app that started from the default Facebook app template provided on heroku. It uses Sinatra instead of Rails and seems to be working fine. But now I want to add in the ability to do some background processing (going through a Facebook user's friends and adding info to my db, etc.) while the user waits on a loading page.

I've tried following the steps listed (see mine below) but I'm hitting this exception:

NameError - uninitialized constant Sinatra::Application::QUEUE:

Here's what I've done:

- added girl_friday to my Gemfile

- ran bundle install successfully

- created the directory /config/initializers/ with file girl_friday.rb:

QUEUE = GirlFriday::WorkQueue.new(:user_client, :size => 3) do |msg|
UserRefresh.process(msg)
end

- created the class UserRefresh in my app.rb file with method process:

class UserRefresh

def process(client)
...
{:value1 => "blah", :value2 => "blahblah"} #return a result
end
end

- called the queue to push some work onto it and use the result upon completion:

QUEUE.push(:client => @client) do |result|
puts result
end

Can someone steer me in the right direction? Is Rails required or can I make this work with just Sinatra and girl_friday?

Thanks!