Exactly the same as after_commit, except it puts the job onto the Sidekiq queue.
Allows you to queue active record methods, after they have been created or updated.
Requires Sidekiq, and Rails >= 6.
Add this line to your application's Gemfile:
gem'delayed_after_commit'And then execute:
$ bundle
Or install it yourself as:
$ gem install delayed_after_commit
classUser < ActiveRecord::BaseincludeDelayedAfterCommitdelayed_after_update:hi_ive_been_updateddelayed_after_create:hi_im_new_around_heredefhi_ive_been_updatedputs"Hi - I've been updated"enddefhi_im_new_around_hereputs"Hi - I've just been created"endendIf you want to invoke the delayed_after_update callback only when an attribute has changed, you must check the attribute change with #previous_changes. Example:
delayed_after_update:geolocate,if: :location_changed?won't invoke geolocate even if #location has changed.
Instead you must do something like
delayed_after_update:geolocate,if: :location_was_changed?deflocation_was_changed?"location".in?previous_changesendThis is necessary because the callback is run after the transaction is committed to the database.
- Allow asyncronous callbacks on destroying objects
Bug reports and pull requests are welcome on GitHub at https://github.com/intellum/delayed_after_commit.