Skip to content

fix(sponsors): dispatch SponsorshipCreated/Removed when sponsorships are attached inline via addSponsor or updateSponsor#548

Merged
smarcet merged 5 commits into
mainfrom
fix/sponsorships-sync
May 20, 2026
Merged

fix(sponsors): dispatch SponsorshipCreated/Removed when sponsorships are attached inline via addSponsor or updateSponsor#548
smarcet merged 5 commits into
mainfrom
fix/sponsorships-sync

Conversation

@romanetar
Copy link
Copy Markdown
Collaborator

@romanetar romanetar commented May 19, 2026

ref https://app.clickup.com/t/86ba0vf07

Summary by CodeRabbit

  • Improvements
    • Sponsorship lifecycle events are now emitted per-sponsorship during sponsor creation and updates, providing more granular and complete event tracking.
  • Tests
    • Added unit tests validating event dispatch types, payloads, and ordering (including creation, update, and removal events).
  • Chore
    • Background job payload and event-type accessors added to support event processing and testing.

Review Change Stack

…are attached inline via addSponsor or updateSponsor

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@romanetar romanetar requested a review from smarcet May 19, 2026 19:08
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 19, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 707c6210-c007-43fa-ba61-4ccaf32efe55

📥 Commits

Reviewing files that changed from the base of the PR and between 9f3f02b and 3bde93d.

📒 Files selected for processing (3)
  • app/Jobs/SponsorServices/PublishSponsorServiceDomainEventsJob.php
  • app/Services/Model/Imp/SummitSponsorService.php
  • tests/Unit/Services/SummitSponsorServiceEventDispatchTest.php

📝 Walkthrough

Walkthrough

SummitSponsorService now collects sponsorship entities created/modified during sponsor transactions and dispatches SponsorCreated/SponsorUpdated plus per-sponsorship SponsorshipCreated/SponsorshipUpdated/SponsorshipRemoved events after the transaction. A job getter API was added and unit tests assert the queued domain event jobs and ordering.

Changes

Sponsorship lifecycle event emission

Layer / File(s) Summary
Event emission in addSponsor
app/Services/Model/Imp/SummitSponsorService.php
Import SummitSponsorshipCreatedEventDTO, collect newly created SummitSponsorship instances into a $new_sponsorships accumulator across sponsorship_id and sponsorships branches, return them from the transaction, then dispatch SponsorDomainEvents::SponsorCreated and SponsorDomainEvents::SponsorshipCreated once per collected sponsorship after the transaction (with per-dispatch logging and error handling).
Event emission in updateSponsor
app/Services/Model/Imp/SummitSponsorService.php
Return sponsor plus $added_sponsorships, $removed_sponsorship_ids, and $updated_sponsorships from the transaction. Track additions, removals, and updates across single sponsorship_id and multi-sponsorships merge paths, then dispatch SponsorDomainEvents::SponsorUpdated and per-sponsorship SponsorshipRemoved (by id), SponsorshipCreated, and SponsorshipUpdated after the transaction (with logging and try/catch).

Support: job API and unit tests

Layer / File(s) Summary
PublishSponsorServiceDomainEventsJob getters
app/Jobs/SponsorServices/PublishSponsorServiceDomainEventsJob.php
Constructor assigns payload and event_type properties and two new public getters getEventType(): string and getPayload(): array expose those values.
Event dispatch unit tests
tests/Unit/Services/SummitSponsorServiceEventDispatchTest.php
New test class seeds summit fixtures, fakes the queue, calls addSponsor/updateSponsor with various sponsorship inputs, and asserts that PublishSponsorServiceDomainEventsJob jobs of types SponsorCreated/SponsorUpdated/SponsorshipCreated/SponsorshipUpdated/SponsorshipRemoved are pushed with valid payload ids and correct ordering where applicable.

🎯 4 (Complex) | ⏱️ ~45 minutes

Suggested reviewers

  • smarcet

Poem

🐰 A sponsor springs to life in the glade,
Events hop out once the transaction's made,
Added, removed, and changed — each one sings,
Jobs in a row like tidy rabbit things,
I nibble logs and watch the messages parade.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 56.25% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: dispatching domain events (SponsorshipCreated/Removed) when sponsorships are attached inline in addSponsor or updateSponsor methods.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/sponsorships-sync

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

📘 OpenAPI / Swagger preview

➡️ https://OpenStackweb.github.io/summit-api/openapi/pr-548/

This page is automatically updated on each push to this PR.

…created) for inline sponsorship events

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

📘 OpenAPI / Swagger preview

➡️ https://OpenStackweb.github.io/summit-api/openapi/pr-548/

This page is automatically updated on each push to this PR.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR ensures sponsor-related domain events are emitted when summit sponsorships are created/removed indirectly via SummitSponsorService::addSponsor() and SummitSponsorService::updateSponsor(), aligning inline attach/update flows with the dedicated sponsorship service’s event publishing.

Changes:

  • Track newly created sponsorship entities during addSponsor() and publish SponsorshipCreated events after the transaction.
  • Track added/removed sponsorship entities during updateSponsor() and publish SponsorshipCreated / SponsorshipRemoved events after the transaction.
  • Add debug logging around the new sponsorship event dispatches.
Comments suppressed due to low confidence (1)

app/Services/Model/Imp/SummitSponsorService.php:210

  • Similar to addSponsor(), $added_sponsorships/$removed_sponsorships are mutated by reference outside the transaction callback. Because the transaction wrapper can retry the callback on reconnectable failures, these arrays can accumulate entries from failed attempts and later dispatch duplicate/incorrect SponsorshipCreated/Removed events. Consider keeping these collections local to the callback and returning them (or explicitly resetting them at the start of each callback execution) to make retries idempotent.
        $added_sponsorships = [];
        $removed_sponsorships = [];

        $sponsor = $this->tx_service->transaction(function () use ($summit, $sponsor_id, $payload, &$added_sponsorships, &$removed_sponsorships) {

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app/Services/Model/Imp/SummitSponsorService.php Outdated
Comment thread app/Services/Model/Imp/SummitSponsorService.php
Comment thread app/Services/Model/Imp/SummitSponsorService.php Outdated
Comment thread app/Services/Model/Imp/SummitSponsorService.php Outdated
Comment thread app/Services/Model/Imp/SummitSponsorService.php Outdated
Copy link
Copy Markdown
Collaborator

@smarcet smarcet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@romanetar please review comments

romanetar and others added 3 commits May 20, 2026 15:17
… prevent duplicate events on retry

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…utates an existing sponsorship type

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: romanetar <roman_ag@hotmail.com>
@github-actions
Copy link
Copy Markdown

📘 OpenAPI / Swagger preview

➡️ https://OpenStackweb.github.io/summit-api/openapi/pr-548/

This page is automatically updated on each push to this PR.

@smarcet smarcet self-requested a review May 20, 2026 14:34
Copy link
Copy Markdown
Collaborator

@smarcet smarcet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@smarcet smarcet merged commit d60f77b into main May 20, 2026
19 checks passed
smarcet pushed a commit that referenced this pull request May 20, 2026
…are attached inline via addSponsor or updateSponsor (#548)

* fix(sponsors): dispatch SponsorshipCreated/Removed when sponsorships are attached inline via addSponsor or updateSponsor

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(sponsors): add debug logs and fix dispatch order (removed before created) for inline sponsorship events

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(sponsors): avoid by-reference capture in transaction callbacks to prevent duplicate events on retry

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(sponsors): dispatch SponsorshipUpdated when sponsorship_id path mutates an existing sponsorship type

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix: review feedback

Signed-off-by: romanetar <roman_ag@hotmail.com>

---------

Signed-off-by: romanetar <roman_ag@hotmail.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants