I hope someone can point out my stupic mistake here as I have wasted
far too much time fiddling with syntax and I just can't get it. I am
new to BackgroundRB and I am trying to pass 2 ids to my worker.

In my controller I have:

MiddleMan.worker(:process_cv_worker).async_changed_cv(:arg =>
{ :vitae_id => @vitae.id, :current_user_id => current_user.id })

And my worker looks like:

class ProcessCvWorker < BackgrounDRb::MetaWorker
set_worker_name :process_cv_worker
require 'pdf/toolkit'

def create(args)
# this method is called, when worker is loaded for the first time
logger.info "Created vitae worker"
end

def changed_cv(arg)
vitae_id = arg[:vitae_id]
user_name = arg[:current_user_id]
@vitae=Vitae.find(vitae_id)

more code

end
end

However, when I run this code I get Error calling method changed_cv
with on worker process_cv_worker at Thu Nov 03 09:37:56 +0000 2011
undefined method `[]' for nil:NilClass

The code works fine if I just use @vitae=Vitae.find(1) so I know that
it is not finding the vitae. I am sure i am being stupid but I have
confused myself and am seeking help.

Thanks,

Dan

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • DanC at Nov 3, 2011 at 10:09 pm
    Sorted

    In my controller
    MiddleMan.worker(:process_cv_worker).async_changed_cv(:args =>
    {:vitae_id => @vitae.id})

    In my worker
    def changed_cv(args)
    @vitae=Vitae.find(args[:vitae_id])

    code

    end

    Dan
    On Nov 3, 9:58 am, DanC wrote:
    I hope someone can point out my stupic mistake here as I have wasted
    far too much time fiddling with syntax and I just can't get it. I am
    new to BackgroundRB and I am trying to pass 2 ids to my worker.

    In my controller I have:

    MiddleMan.worker(:process_cv_worker).async_changed_cv(:arg =>
    { :vitae_id => @vitae.id, :current_user_id => current_user.id })

    And my worker looks like:

    class ProcessCvWorker < BackgrounDRb::MetaWorker
    set_worker_name :process_cv_worker
    require 'pdf/toolkit'

    def create(args)
    # this method is called, when worker is loaded for the first time
    logger.info "Created vitae worker"
    end

    def changed_cv(arg)
    vitae_id = arg[:vitae_id]
    user_name = arg[:current_user_id]
    @vitae=Vitae.find(vitae_id)

    more code

    end
    end

    However, when I run this code I get Error calling method changed_cv
    with on worker process_cv_worker at Thu Nov 03 09:37:56 +0000 2011
    undefined method `[]' for nil:NilClass

    The code works fine if I just use @vitae=Vitae.find(1) so I know that
    it is not finding the vitae. I am sure i am being stupid but I have
    confused myself and am seeking help.

    Thanks,

    Dan
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Kevin at Nov 3, 2011 at 11:45 pm
    I do not know if this can help you , but i do experence this kind of things few days ago.

    The rails process create the record and return the id for you, notice the db not commit actually at this monument, then spawn/fork the worker process, the worker found the record not exist in DB.

    If you experence the same problem, i recommend you there is a plugin/gem that include
    after_commit callback, and make the async work after the db commit.



    --
    kevin
    Sent with Sparrow (http://www.sparrowmailapp.com/?sig)

    On Thursday, November 3, 2011 at 5:58 PM, DanC wrote:

    I hope someone can point out my stupic mistake here as I have wasted
    far too much time fiddling with syntax and I just can't get it. I am
    new to BackgroundRB and I am trying to pass 2 ids to my worker.

    In my controller I have:

    MiddleMan.worker(:process_cv_worker).async_changed_cv(:arg =>
    { :vitae_id => @vitae.id, :current_user_id => current_user.id })

    And my worker looks like:

    class ProcessCvWorker < BackgrounDRb::MetaWorker
    set_worker_name :process_cv_worker
    require 'pdf/toolkit'

    def create(args)
    # this method is called, when worker is loaded for the first time
    logger.info (http://logger.info) "Created vitae worker"
    end

    def changed_cv(arg)
    vitae_id = arg[:vitae_id]
    user_name = arg[:current_user_id]
    @vitae=Vitae.find(vitae_id)

    more code

    end
    end

    However, when I run this code I get Error calling method changed_cv
    with on worker process_cv_worker at Thu Nov 03 09:37:56 +0000 2011
    undefined method `[]' for nil:NilClass

    The code works fine if I just use @vitae=Vitae.find(1) so I know that
    it is not finding the vitae. I am sure i am being stupid but I have
    confused myself and am seeking help.

    Thanks,

    Dan

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com (mailto:rubyonrails-talk@googlegroups.com).
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com (mailto:rubyonrails-talk+unsubscribe@googlegroups.com).
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedNov 3, '11 at 10:09a
activeNov 3, '11 at 11:45p
posts3
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

DanC: 2 posts Kevin: 1 post

People

Translate

site design / logo © 2022 Grokbase