Skip to content

Commit 72c2ec1

Browse files
committed
add comments
1 parent de26a00 commit 72c2ec1

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

lib/rails/enqueue_job_in_after_commit_callback.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def send_notification
2929
```
3030
EOS
3131

32+
# find all job classes and mailer classes
3233
definitions = call_helper 'ruby/parse'
3334
job_classes = definitions.find_classes_by_ancestor('ApplicationJob').map(&:full_name) +
3435
definitions.find_classes_by_ancestor('Sidekiq::Job').map(&:full_name)
@@ -39,11 +40,14 @@ def send_notification
3940
callback_names_with_actions = {}
4041
job_performed_def_names = []
4142

43+
# find after_create, after_update, after_save callbacks,
44+
# and remember InsertAction to insert _commit to the callback name
4245
find_node node_type: 'call_node', receiver: nil, name: { in: %i[after_create after_update after_save] } do
4346
callback_names_with_actions[node.arguments.arguments.first.to_value.to_s] =
4447
NodeMutation::InsertAction.new(node, '_commit', to: :name, adapter: mutation_adapter)
4548
end
4649

50+
# find method names that perform a job or deliver a mailer
4751
find_node node_type: 'def_node' do
4852
if_exist_node ".call_node[receiver=~/\\A(#{job_classes.join('|')})/][name IN (perform_later perform_async perform_in perform_at)]" do
4953
job_performed_def_names << node.name.to_s
@@ -53,6 +57,8 @@ def send_notification
5357
end
5458
end
5559

60+
# check if the callback method performs a job or deliver a mailer,
61+
# if so, add the InsertAction
5662
class_definition = definitions.find_class_by_full_name(node.full_name)
5763
callback_names_with_actions.each do |callback_name, action|
5864
if job_performed_def_names.include?(callback_name)

0 commit comments

Comments
 (0)