Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The tracked callback should be implemented using after_commit instead of after_create/after_update #99

Closed
Looooong opened this issue Jan 10, 2019 · 11 comments

Comments

@Looooong
Copy link

Looooong commented Jan 10, 2019

Whenever notify_later or send_later is enabled in the tracked option on a notifiable, a job is enqueued to be processed. However, in some instance, the job back-end may process the job before the notifiable is persisted in the database. This results in exception on the job back-end.

I suggest that this code:

def add_tracked_callback(tracked_callbacks, tracked_action, tracked_proc)
if tracked_callbacks.include? tracked_action
case tracked_action
when :create
after_create tracked_proc
when :update
after_update tracked_proc
end
end
end

should be replaced with:

 def add_tracked_callback(tracked_callbacks, tracked_action, tracked_proc) 
   if tracked_callbacks.include? tracked_action 
     after_commit(tracked_proc, on: tracked_action) 
   end 
 end 
@Looooong Looooong changed the title The tracked option should use after_commit instead of after_save The tracked callback should be implemented using after_commit instead of after_create/after_update Jan 10, 2019
@irondnb
Copy link

irondnb commented Mar 11, 2019

Totally agree, as after_commit callback ensures that transaction is finished and object persist in database. Im using override in initializer to avoid this problem.

@simukappu
Copy link
Owner

Can you create a pull request for this?

@Looooong
Copy link
Author

I opened #100, but couldn't run the test because of dependency issue. Can you check that out?

@simukappu
Copy link
Owner

Thank you for your PR. As you mentioned, we have to pass the tests. It seems to be more than just dependency issue.
https://travis-ci.org/simukappu/activity_notification/builds/504662767

@simukappu
Copy link
Owner

I have fixed this dependency issue for testing in this commit.
For now, it is fixed in master and development branches.

@Looooong, can you check this pull request again?

@simukappu
Copy link
Owner

@Looooong
Copy link
Author

@simukappu I have modified the pull requests. And somehow, a few tests only in Rails 5.1 are failed. I wonder if it's Rails specific error?

@irondnb
Copy link

irondnb commented Apr 16, 2019

@simukappu I have modified the pull requests. And somehow, a few tests only in Rails 5.1 are failed. I wonder if it's Rails specific error?

Actually there was issue with after_commit for 5.1.x. It was fixed on 5.1-stable

rails/rails#30779
rails/rails#32176

@Looooong
Copy link
Author

@irondnb Thank you for the information. I couldn't get my head around this. Is there anything we can do to solve this problem?

@simukappu
Copy link
Owner

@Looooong I avoided this Rails issue with above commit and will merge your PR. Thank you for your contribution!

@simukappu
Copy link
Owner

Just released as v1.7.1. Thanks!

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

No branches or pull requests

3 participants