-
-
Notifications
You must be signed in to change notification settings - Fork 199
fix: handle duplicate InvitationLogEntry creation on retry #2556
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,36 +22,37 @@ def start_batch | |
| def log_success(member, invitation = nil) | ||
| return unless @log | ||
|
|
||
| @log.entries.create!( | ||
| member: member, | ||
| invitation: invitation, | ||
| status: :success, | ||
| processed_at: Time.current | ||
| ).tap { @log.increment!(:success_count) } | ||
| entry = find_or_build_entry(member, invitation, :success) | ||
| return entry if entry.persisted? | ||
|
|
||
| entry.assign_attributes(processed_at: Time.current) | ||
| save_entry(entry, :success_count) | ||
| end | ||
|
|
||
| def log_failure(member, invitation, error) | ||
| return unless @log | ||
|
|
||
| @log.entries.create!( | ||
| member: member, | ||
| invitation: invitation, | ||
| status: :failed, | ||
| entry = find_or_build_entry(member, invitation, :failed) | ||
| return entry if entry.persisted? | ||
|
|
||
| entry.assign_attributes( | ||
| failure_reason: error.message, | ||
| processed_at: Time.current | ||
| ).tap { @log.increment!(:failure_count) } | ||
| ) | ||
| save_entry(entry, :failure_count) | ||
| end | ||
|
|
||
| def log_skipped(member, invitation, reason) | ||
| return unless @log | ||
|
|
||
| @log.entries.create!( | ||
| member: member, | ||
| invitation: invitation, | ||
| status: :skipped, | ||
| entry = find_or_build_entry(member, invitation, :skipped) | ||
| return entry if entry.persisted? | ||
|
|
||
| entry.assign_attributes( | ||
| failure_reason: reason, | ||
| processed_at: Time.current | ||
| ).tap { @log.increment!(:skipped_count) } | ||
| ) | ||
| save_entry(entry, :skipped_count) | ||
| end | ||
|
|
||
| def finish_batch(total_invitees) | ||
|
|
@@ -74,5 +75,21 @@ def fail_batch(error) | |
| ) | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def find_or_build_entry(member, invitation, status) | ||
| @log.entries.find_or_initialize_by( | ||
| member:, | ||
| invitation:, | ||
| status: | ||
| ) | ||
| end | ||
|
|
||
| def save_entry(entry, counter) | ||
| entry.save! | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @till, Good question! I have considered this carefully, and I believe Why the current approach is correct:
Happy to discuss further if you think there is a real scenario I am missing!
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @till, Good question! I have considered this carefully, and I believe Why the current approach is correct:
Happy to discuss further if you think there is a real scenario I am missing! |
||
| @log.increment!(counter) | ||
| entry | ||
| end | ||
|
|
||
| attr_reader :log | ||
| end | ||
Uh oh!
There was an error while loading. Please reload this page.