1

I've been unable to work with an object within code triggered from a Resque worker. This is a sinatra/datamapper app. The Feed class is a DataMapper model. Here's the Subscriber code

class Subscriber
  @queue = :subscriptions_queue

  def self.perform(feed_id)
    feed = Feed.get(feed_id)
    feed.subscribe()
  end
end

Working well, up until the subscribe() method executes

class Feed
  def subscribe    
    feed = Feedzirra::Feed.fetch_and_parse(url)
    raise feed.description
  end
end

Which results in an error:

** [23:09:44 2012-08-02] 32028: (Job{subscriptions_queue} | Subscriber | [2]) failed: #<NoMethodError: undefined method `description' for #<Hash:0x007fa6f4b97e48>>

Why would that be a hash? I can call inspect on the feed object:

class Feed
  def subscribe    
    feed = Feedzirra::Feed.fetch_and_parse(url)
    raise feed.inspect
  end
end

which dumps the feed as one would expect:

** [23:01:31 2012-08-02] 32010: (Job{subscriptions_queue} | Subscriber | [2]) failed: #<RuntimeError: {#<Addressable::URI:0x3fefd45f2fb8 URI:http://feeds.feedburner.com/scoutapp>=>#<Feedzirra::Parser::RSSFeedBurner:0x007fdfaa024f18 @title="Scout ~ The Blog", @url="http://blog.scoutapp.com/", @description="Scout ~ The Blog", @hubs=["http://pubsubhubbub.appspot.com/"], @entries=

See any areas to look at?

RyanW
  • 5,338
  • 4
  • 46
  • 58

1 Answers1

1

It's actually an hash with a pair of Addressable::URI => Feedzirra::Parser::RSSFeedBurner

if you don't know how to get that URI object just do feed[feed.keys[0]].description or feed.values[0]

Also checking the github repo it seems you should have a entries method. This happens if you are fetching from the root url. So you might be able to do feeds.entries.first if you only want to get the first.

Ismael Abreu
  • 16,443
  • 6
  • 61
  • 75
  • Still seems odd, if I execute the same code in irb, and call .inspect it's just a (not a hash pair) => "# – RyanW Aug 03 '12 at 06:38
  • Ahh, I see now, my url property on the Feed class is an Addressable::URI, and Feedzirra will return the hash if the url is anything but a string. In irb, I was using strings. Thanks for the hint! – RyanW Aug 03 '12 at 06:49