Hello Jeremy,
As the subject says, is there a way to check if record was created xor
updated in the after_commit hook?
We've been using after_create but that introduced race conditions with
background jobs.
I saw there is a @was_new variable, which is true in the after_create but
nil in after_commit.
Right now I've come up with a workaround:
class Activity < Sequel::Model
def before_create
super
@just_created = true
end
def after_commit
if @just_created
notify
@just_created = false
end
end
def notify
print "Queueing notification job for activity #{ id }..."
job_id = NotificationWorker.perform_async(id)
puts " #{ job_id }"
end
end
Thank you,
Ollie
--
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/d/optout.