Closed yjukaku closed 10 years ago
can you show the code that kicks off the job?
On Tuesday, August 5, 2014, yjukaku notifications@github.com wrote:
Should you pass ActiveRecord objects to jobs? I feel like this would be an issue, rather than sending a model's id and looking it up from the job.
Unfortunately, if I do pass in an id, my specs fail because the inlined nature of the spec's job causes the job to look up the model before it is actually committed to the database.
ex.
def create @book = Book.new(params[:book]) if @book.save DownloadBookJob.new.async(@book) #vs DownloadBookJob.new.async(@book.id), which doesn't work in specs because the book hasn't been committed to the DB yet. end end
— Reply to this email directly or view it on GitHub https://github.com/brandonhilkert/sucker_punch/issues/69.
_The Build a Ruby Gem guide is available! http://brandonhilkert.com/books/build-a-ruby-gem/?utm_source=gmail-sig&utm_medium=email&utm_campaign=gem-config_
Sorry, that is the code that kicks off the job. I edited the code to add
the call to perform
.
On Aug 5, 2014 3:36 PM, "Brandon Hilkert" notifications@github.com wrote:
can you show the code that kicks off the job?
On Tuesday, August 5, 2014, yjukaku notifications@github.com wrote:
Should you pass ActiveRecord objects to jobs? I feel like this would be an issue, rather than sending a model's id and looking it up from the job.
Unfortunately, if I do pass in an id, my specs fail because the inlined nature of the spec's job causes the job to look up the model before it is actually committed to the database.
ex.
def create @book = Book.new(params[:book]) if @book.save DownloadBookJob.new.async(@book) #vs DownloadBookJob.new.async(@book.id), which doesn't work in specs because the book hasn't been committed to the DB yet. end end
— Reply to this email directly or view it on GitHub https://github.com/brandonhilkert/sucker_punch/issues/69.
_The Build a Ruby Gem guide is available! < http://brandonhilkert.com/books/build-a-ruby-gem/?utm_source=gmail-sig&utm_medium=email&utm_campaign=gem-config>_
— Reply to this email directly or view it on GitHub https://github.com/brandonhilkert/sucker_punch/issues/69#issuecomment-51248170 .
See the section "cannot find ModelName..."
https://github.com/mperham/sidekiq/wiki/Problems-and-Troubleshooting
On Tuesday, August 5, 2014, yjukaku notifications@github.com wrote:
Sorry, that is the code that kicks off the job. I edited the code to add the call to
perform
. On Aug 5, 2014 3:36 PM, "Brandon Hilkert" <notifications@github.com javascript:_e(%7B%7D,'cvml','notifications@github.com');> wrote:can you show the code that kicks off the job?
On Tuesday, August 5, 2014, yjukaku <notifications@github.com javascript:_e(%7B%7D,'cvml','notifications@github.com');> wrote:
Should you pass ActiveRecord objects to jobs? I feel like this would be an issue, rather than sending a model's id and looking it up from the job.
Unfortunately, if I do pass in an id, my specs fail because the inlined nature of the spec's job causes the job to look up the model before it is actually committed to the database.
ex.
def create @book = Book.new(params[:book]) if @book.save DownloadBookJob.new.async(@book) #vs DownloadBookJob.new.async(@ book.id), which doesn't work in specs because the book hasn't been committed to the DB yet. end end
— Reply to this email directly or view it on GitHub https://github.com/brandonhilkert/sucker_punch/issues/69.
*The Build a Ruby Gem guide is available! <
— Reply to this email directly or view it on GitHub < https://github.com/brandonhilkert/sucker_punch/issues/69#issuecomment-51248170>
.
— Reply to this email directly or view it on GitHub https://github.com/brandonhilkert/sucker_punch/issues/69#issuecomment-51252094 .
_The Build a Ruby Gem guide is available! http://brandonhilkert.com/books/build-a-ruby-gem/?utm_source=gmail-sig&utm_medium=email&utm_campaign=gem-config_
Thanks, I had actually read that but I didn't want to use an after_commit hook because the background task isn't really encapsulated by the model.
Hmm... On Aug 5, 2014 4:50 PM, "Brandon Hilkert" notifications@github.com wrote:
See the section "cannot find ModelName..."
https://github.com/mperham/sidekiq/wiki/Problems-and-Troubleshooting
On Tuesday, August 5, 2014, yjukaku notifications@github.com wrote:
Sorry, that is the code that kicks off the job. I edited the code to add the call to
perform
. On Aug 5, 2014 3:36 PM, "Brandon Hilkert" <notifications@github.com javascript:_e(%7B%7D,'cvml','notifications@github.com');> wrote:can you show the code that kicks off the job?
On Tuesday, August 5, 2014, yjukaku <notifications@github.com javascript:_e(%7B%7D,'cvml','notifications@github.com');> wrote:
Should you pass ActiveRecord objects to jobs? I feel like this would be an issue, rather than sending a model's id and looking it up from the job.
Unfortunately, if I do pass in an id, my specs fail because the inlined nature of the spec's job causes the job to look up the model before it is actually committed to the database.
ex.
def create @book = Book.new(params[:book]) if @book.save DownloadBookJob.new.async(@book) #vs DownloadBookJob.new.async(@ book.id), which doesn't work in specs because the book hasn't been committed to the DB yet. end end
— Reply to this email directly or view it on GitHub https://github.com/brandonhilkert/sucker_punch/issues/69.
*The Build a Ruby Gem guide is available! <
— Reply to this email directly or view it on GitHub <
https://github.com/brandonhilkert/sucker_punch/issues/69#issuecomment-51248170>
.
— Reply to this email directly or view it on GitHub < https://github.com/brandonhilkert/sucker_punch/issues/69#issuecomment-51252094>
.
_The Build a Ruby Gem guide is available! < http://brandonhilkert.com/books/build-a-ruby-gem/?utm_source=gmail-sig&utm_medium=email&utm_campaign=gem-config>_
— Reply to this email directly or view it on GitHub https://github.com/brandonhilkert/sucker_punch/issues/69#issuecomment-51257767 .
Should you pass ActiveRecord objects to jobs? I feel like this would be an issue, rather than sending a model's id and looking it up from the job.
Unfortunately, if I do pass in an id, my specs fail because the inlined nature of the spec's job causes the job to look up the model before it is actually committed to the database.
ex.