Skip to content

feat: publish media file type lifecycle events to sponsor services#492

Open
romanetar wants to merge 2 commits into
mainfrom
feature/publish-media-file-type-domain-events
Open

feat: publish media file type lifecycle events to sponsor services#492
romanetar wants to merge 2 commits into
mainfrom
feature/publish-media-file-type-domain-events

Conversation

@romanetar
Copy link
Copy Markdown
Collaborator

@romanetar romanetar commented Feb 3, 2026

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

Summary by CodeRabbit

  • New Features

    • Added domain events and a serializer for media file type create/update/delete to support cross-service notifications.
  • Refactor

    • Moved all domain-event dispatches to occur after database transactions complete, improving event delivery reliability and consistency across services.

Review Change Stack

Comment thread app/Events/SponsorServices/SummitMediaFileTypeCreatedEventDTO.php Outdated
Comment thread app/Events/SponsorServices/SummitMediaFileTypeCreatedEventDTO.php
Comment thread app/Services/Model/Imp/SummitMediaFileTypeService.php Outdated
Comment thread app/Services/Model/Imp/SummitMediaFileTypeService.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

@romanetar romanetar force-pushed the feature/publish-media-file-type-domain-events branch from dd56c7d to 8021df8 Compare April 10, 2026 17:04
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 10, 2026

Caution

Review failed

Failed to post review comments

📝 Walkthrough

Walkthrough

Adds media-file-type event DTO and constants; refactors multiple services to capture entities inside DB transactions and dispatch PublishSponsorServiceDomainEventsJob after transaction commit; updates queue comment list.

Changes

New Event Infrastructure

Layer / File(s) Summary
Event DTO and domain event constants
app/Events/SponsorServices/SummitMediaFileTypeCreatedEventDTO.php, app/Events/SponsorServices/SummitMediaFileTypeDomainEvents.php
Adds SummitMediaFileTypeCreatedEventDTO with factory and serialize() and defines summit_media_file_type_created/updated/deleted constants.

Service Refactoring - Transaction Boundaries

Layer / File(s) Summary
SummitMediaFileTypeService: add/update/delete
app/Services/Model/Imp/SummitMediaFileTypeService.php
Capture created/updated/deleted entity from transaction, dispatch PublishSponsorServiceDomainEventsJob after commit using DTO payloads; docblocks updated with @throws \Exception.
Summit update/delete
app/Services/Model/Imp/SummitService.php
Return populated Summit from transaction and move PublishSponsorServiceDomainEventsJob::dispatch(...) outside the transaction for update and delete.
Sponsor delete
app/Services/Model/Imp/SummitSponsorService.php
Transaction now returns removed sponsor entity; SponsorDeleted dispatch moved after transaction.
Sponsorship add/update/remove and add-on flows
app/Services/Model/Imp/SummitSponsorshipService.php
Transactional closures return created/updated/removed entities and all PublishSponsorServiceDomainEventsJob dispatches are executed after transaction commit (sponsor, sponsorship, add-on events captured and dispatched post-commit).

Configuration

Layer / File(s) Summary
Queue docs
config/queue.php
Adds summit_media_file_type_created, summit_media_file_type_updated, and summit_media_file_type_deleted to the documented domain event list for the message broker connection (comments only).

Sequence Diagram(s)

sequenceDiagram
  participant Service as SummitMediaFileTypeService
  participant Tx as TxService
  participant Repo as Repository/DB
  participant Job as PublishSponsorServiceDomainEventsJob
  participant Broker as MessageBroker

  Service->>Tx: begin transaction (closure performs mutations)
  Tx->>Repo: persist/update/delete entities
  Tx-->>Service: return created/updated/deleted entity (after commit)
  Service->>Job: dispatch(domain_event_name, dto_payload)
  Job->>Broker: send message to domain events exchange
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Suggested reviewers

  • smarcet

Poem

🐰 I hopped through code where transactions lay,
Captured the creatures before they stray,
Then waited for the commit to sing,
And sent out events on joyous spring,
Now messages hop free, one, two, three!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: introducing domain event publishing for summit media file type lifecycle events (created, updated, deleted) to sponsor services.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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 feature/publish-media-file-type-domain-events

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.

@romanetar romanetar requested a review from smarcet April 10, 2026 17:05
@github-actions
Copy link
Copy Markdown

📘 OpenAPI / Swagger preview

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

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

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
app/Services/Model/Imp/SummitMediaFileTypeService.php (1)

86-91: ⚠️ Potential issue | 🔴 Critical

Don't overwrite the entity being updated during the uniqueness check.

When name is present and unique, Line 87 replaces $type with the lookup result (null), so Line 91 ends up calling SummitMediaFileTypeFactory::populate(null, $payload). Use a separate variable for the duplicate-name lookup.

🐛 Proposed fix
-            if(isset($payload['name'])){
-                $type = $this->repository->getByName(trim($payload['name']));
-                if(!is_null($type) && $type->getId() != $id)
+            if(isset($payload['name'])){
+                $existingType = $this->repository->getByName(trim($payload['name']));
+                if(!is_null($existingType) && $existingType->getId() != $id)
                     throw new ValidationException(sprintf("Name %s already exists.", $payload['name']));
             }
             return SummitMediaFileTypeFactory::populate($type, $payload);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@app/Services/Model/Imp/SummitMediaFileTypeService.php` around lines 86 - 91,
The uniqueness check in SummitMediaFileTypeService is overwriting the entity
being updated by reusing $type for the repository lookup; change the
duplicate-name lookup to use a separate variable (e.g. $existing or $duplicate)
when calling $this->repository->getByName(trim($payload['name'])) so you can
compare IDs (existing->getId() != $id) and only throw ValidationException on
conflict, then return SummitMediaFileTypeFactory::populate($type, $payload)
using the original $type entity.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@app/Services/Model/Imp/SummitMediaFileTypeService.php`:
- Around line 66-68: The code currently calls
PublishSponsorServiceDomainEventsJob::dispatch with
SummitMediaFileTypeCreatedEventDTO::fromSummitMediaFileType(...)->serialize()
and SummitMediaFileTypeDomainEvents::SummitMediaFileTypeCreated after the DB
write, which can still fail and lose the event; replace these direct post-commit
dispatches with a durable outbox write inside the same transaction:
create/persist an Outbox record (event_type, payload, aggregate_id, status,
queued_at) when creating/updating the SummitMediaFileType (use the same spots
where PublishSponsorServiceDomainEventsJob::dispatch is invoked), remove the
immediate dispatch call, and let a separate idempotent background worker/cron
read pending Outbox rows and call PublishSponsorServiceDomainEventsJob (or the
publisher) to dispatch and then mark Outbox rows as published/failed; ensure
payload uses SummitMediaFileTypeCreatedEventDTO::fromSummitMediaFileType
serialization and include unique aggregate/event identifiers for idempotency.

---

Outside diff comments:
In `@app/Services/Model/Imp/SummitMediaFileTypeService.php`:
- Around line 86-91: The uniqueness check in SummitMediaFileTypeService is
overwriting the entity being updated by reusing $type for the repository lookup;
change the duplicate-name lookup to use a separate variable (e.g. $existing or
$duplicate) when calling $this->repository->getByName(trim($payload['name'])) so
you can compare IDs (existing->getId() != $id) and only throw
ValidationException on conflict, then return
SummitMediaFileTypeFactory::populate($type, $payload) using the original $type
entity.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e7c93c88-4afd-44c9-9f7b-1b9f4c08e83e

📥 Commits

Reviewing files that changed from the base of the PR and between 2404a30 and 8021df8.

📒 Files selected for processing (7)
  • app/Events/SponsorServices/SummitMediaFileTypeCreatedEventDTO.php
  • app/Events/SponsorServices/SummitMediaFileTypeDomainEvents.php
  • app/Services/Model/Imp/SummitMediaFileTypeService.php
  • app/Services/Model/Imp/SummitService.php
  • app/Services/Model/Imp/SummitSponsorService.php
  • app/Services/Model/Imp/SummitSponsorshipService.php
  • config/queue.php

Comment on lines +66 to +68
PublishSponsorServiceDomainEventsJob::dispatch(
SummitMediaFileTypeCreatedEventDTO::fromSummitMediaFileType($media_file_type)->serialize(),
SummitMediaFileTypeDomainEvents::SummitMediaFileTypeCreated);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Use a durable outbox for these domain events.

Moving the dispatch out of the transaction fixes the rollback problem, but these calls can still fail after the write has committed. That leaves Summit Media File Type state persisted here while downstream sponsor services never receive the matching lifecycle event. The same failure mode applies to the analogous post-commit dispatches introduced in the other services in this PR.

Also applies to: 94-96, 119-121

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@app/Services/Model/Imp/SummitMediaFileTypeService.php` around lines 66 - 68,
The code currently calls PublishSponsorServiceDomainEventsJob::dispatch with
SummitMediaFileTypeCreatedEventDTO::fromSummitMediaFileType(...)->serialize()
and SummitMediaFileTypeDomainEvents::SummitMediaFileTypeCreated after the DB
write, which can still fail and lose the event; replace these direct post-commit
dispatches with a durable outbox write inside the same transaction:
create/persist an Outbox record (event_type, payload, aggregate_id, status,
queued_at) when creating/updating the SummitMediaFileType (use the same spots
where PublishSponsorServiceDomainEventsJob::dispatch is invoked), remove the
immediate dispatch call, and let a separate idempotent background worker/cron
read pending Outbox rows and call PublishSponsorServiceDomainEventsJob (or the
publisher) to dispatch and then mark Outbox rows as published/failed; ensure
payload uses SummitMediaFileTypeCreatedEventDTO::fromSummitMediaFileType
serialization and include unique aggregate/event identifiers for idempotency.

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

romanetar added 2 commits May 22, 2026 15:59
Signed-off-by: romanetar <roman_ag@hotmail.com>
Signed-off-by: romanetar <roman_ag@hotmail.com>
@romanetar romanetar force-pushed the feature/publish-media-file-type-domain-events branch from 8021df8 to eddaa78 Compare May 22, 2026 14:05
@github-actions
Copy link
Copy Markdown

📘 OpenAPI / Swagger preview

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

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

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.

2 participants