feat: publish media file type lifecycle events to sponsor services#492
feat: publish media file type lifecycle events to sponsor services#492romanetar wants to merge 2 commits into
Conversation
smarcet
left a comment
There was a problem hiding this comment.
@romanetar please review
dd56c7d to
8021df8
Compare
|
Caution Review failedFailed to post review comments 📝 WalkthroughWalkthroughAdds 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. ChangesNew Event Infrastructure
Service Refactoring - Transaction Boundaries
Configuration
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
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
|
📘 OpenAPI / Swagger preview ➡️ https://OpenStackweb.github.io/summit-api/openapi/pr-492/ This page is automatically updated on each push to this PR. |
There was a problem hiding this comment.
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 | 🔴 CriticalDon't overwrite the entity being updated during the uniqueness check.
When
nameis present and unique, Line 87 replaces$typewith the lookup result (null), so Line 91 ends up callingSummitMediaFileTypeFactory::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
📒 Files selected for processing (7)
app/Events/SponsorServices/SummitMediaFileTypeCreatedEventDTO.phpapp/Events/SponsorServices/SummitMediaFileTypeDomainEvents.phpapp/Services/Model/Imp/SummitMediaFileTypeService.phpapp/Services/Model/Imp/SummitService.phpapp/Services/Model/Imp/SummitSponsorService.phpapp/Services/Model/Imp/SummitSponsorshipService.phpconfig/queue.php
| PublishSponsorServiceDomainEventsJob::dispatch( | ||
| SummitMediaFileTypeCreatedEventDTO::fromSummitMediaFileType($media_file_type)->serialize(), | ||
| SummitMediaFileTypeDomainEvents::SummitMediaFileTypeCreated); |
There was a problem hiding this comment.
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.
Signed-off-by: romanetar <roman_ag@hotmail.com>
Signed-off-by: romanetar <roman_ag@hotmail.com>
8021df8 to
eddaa78
Compare
|
📘 OpenAPI / Swagger preview ➡️ https://OpenStackweb.github.io/summit-api/openapi/pr-492/ This page is automatically updated on each push to this PR. |
ref https://app.clickup.com/t/86b79912c
Summary by CodeRabbit
New Features
Refactor