Hi there,

Only after I opened an issue at Github I realized I should have posted this 
here before, sorry about that...

>From Sequel documentation re: Model Hooks:

So when a model object is created, you want to add a background job that 
will create the thumbnail for the picture. If you used after_save for this 
and transactions are being used, you are subject to a race condition where 
the background job library will check the database table for the record 
before the transaction that saved the record commits, and it won't be able 
to see the record's data. Using after_commit, you are guaranteed that the 
background job library will not get notified of the record until after the 
transaction commits and the data is viewable.

Unless I'm missing something, there is no built-in way to check if the 
current record was new on an after_commit hook. I have a use case where I 
need to perform a background job only for new records, so in the after_savehook 
I'm setting my own flag based on 
@was_new.

Here we can see that @was_new is reset just before the after_commit hook 
runs:
https://github.com/jeremyevans/sequel/blob/master/lib/sequel/model/base.rb#L1656-L1665

Could we make @was_new available in the after_commit hook? Or is there 
another to achieve this?
Thank you,
Pedro Padron
 

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to