Model.new is missing in rails #44

Closed
erickhsiao opened this Issue Dec 1, 2011 · 8 comments

Comments

Projects
None yet
3 participants

as title. when I run lots of works with one job, it sometime shows

Job Error  -> undefined method `new' on nil:NilClass.

my environment is rbx with 1.9.3
(let me make sure, just rvm rbx and type "rbx -X19 -v" and would change to ruby 1.9.3 right?)

and I also added

GirlFriday::WorkQueue.immediate!

into any place that it should be..
but still doesn't works.

Collaborator

jc00ke commented Dec 1, 2011

Hmm. Well first, we don't officially support rbx, though I hope we will someday. And since 1.9 support in rbx is still a work in progress. What happens when you run it in 1.8 mode?

Is there a chance we could see your code or maybe you could distill an example that fails? How are your models being fetched?

Owner

mperham commented Dec 2, 2011

A backtrace and the code around the error location would be useful.

Hi. here is the code, I tried to move GirlFriday::WorkQueue.immediate! around but didn't work..
thanks so much.. @@

Member.rb (model)

def self.setup(rg,rgi)
      members=Member.where("fbid=?",rg[:me]["id"])
      if members.count<1
          member=self.create(:fbid=>rg[:me]["id"])
          FBJOB_FRIENDLIST_QUEUE.push(:member=>member,:rg=>rg,:rgi=>rgi)
          GirlFriday::WorkQueue.immediate!
      end
 end 

girl_friday.rb

FBJOB_FRIENDLIST_QUEUE = GirlFriday::WorkQueue.new(:gffriendlist,:size=>500) do |opts|
    MemberFbfriend.import_friends_from_fb(opts[:member],opts[:rg],opts[:rgi])
end

MemberFbfriend.rb (Model)

def self.import_friends_from_fb(member,rg,rgInstance)
    friends=rgInstance.get("me/friends")["data"]
    friends.each{|fbfriend|
      begin
      fbfriendObjs=Member.where("fbid=?",fbfriend["id"])
      if fbfriendObjs && fbfriendObjs.count>0
                fbfriendObj=fbfriendObjs.first
      else
                friendFbData=rgInstance.get("#{fbfriend["id"]}")
                fbfriendObj=Member.new(:fbid=>fbfriend["id"])
                fbfriendObj.save
          end
       rescue Exception=>e
          puts "why error =>  #{e}"
       end
 }
end

and error in import_friends_from_fb is like :

undefined method `new' on nil:NilClass.
Owner

mperham commented Dec 2, 2011

The call to immediate should be done before you declare your queue in girl_friday.rb. It globally changes GF's behavior.

On Dec 2, 2011, at 8:15 AM, erickhsiaoreply@reply.github.com wrote:

Hi. here is the code, I tried to move GirlFriday::WorkQueue.immediate! around but didn't work..
thanks so much.. @@

Member.rb (model)

def self.setup(rg,rgi)
members=Member.where("fbid=?",rg[:me]["id"])
if members.count<1
member=self.create(:fbid=>rg[:me]["id"])
FBJOB_FRIENDLIST_QUEUE.push(:member=>member,:rg=>rg,:rgi=>rgi)
GirlFriday::WorkQueue.immediate!
end
end

girl_friday.rb

FBJOB_FRIENDLIST_QUEUE = GirlFriday::WorkQueue.new(:gffriendlist,:size=>500) do |opts|
MemberFbfriend.import_friends_from_fb(opts[:member],opts[:rg],opts[:rgi])
end

MemberFbfriend.rb (Model)

def self.import_friends_from_fb(member,rg,rgInstance)
friends=rgInstance.get("me/friends")["data"]
friends.each{|fbfriend|
begin
fbfriendObjs=Member.where("fbid=?",fbfriend["id"])
if fbfriendObjs && fbfriendObjs.count>0
fbfriendObj=fbfriendObjs.first
else
friendFbData=rgInstance.get("#{fbfriend["id"]}")
fbfriendObj=Member.new(:fbid=>fbfriend["id"])
fbfriendObj.save
end
rescue Exception=>e
puts "why error => #{e}"
end
}
end

and error in import_friends_from_fb is like :

undefined method `new' on nil:NilClass.


Reply to this email directly or view it on GitHub:
#44 (comment)

ok.. let me try.. thanks.. :)

it took too and killed - -

E, [2011-12-03T00:23:42.779992 #15716] ERROR -- : worker=0 PID:15853 timeout (61s > 60s), killing
E, [2011-12-03T00:23:43.060474 #15716] ERROR -- : reaped #<Process::Status:0x11940 @termsig=9 @stopsig=nil @pid=15853 @exitstatus=nil> worker=0
Owner

mperham commented Dec 2, 2011

That means the background job took girl_friday more than 60 seconds to process. You'll either need to speed up the job, turn off development mode autoloading or pass the job to a true background system like Resque.

Collaborator

jc00ke commented May 7, 2012

Please reopen if you're still seeing this issue.

@jc00ke jc00ke closed this May 7, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment