🔄 Refactor: VATSIM.net Webhook Processing (Improved Observability & Safety)#4545
🔄 Refactor: VATSIM.net Webhook Processing (Improved Observability & Safety)#4545MrAdder wants to merge 14 commits intoVATSIM-UK:mainfrom
Conversation
|
^ The Failing check is a Github issue not myself |
|
@AxonC or @kristiankunc I have tested this as best as possible however I do not have Webhook permissions with VatsimDev if one of you could test this that would be great. |
There was a problem hiding this comment.
Pull request overview
Refactors the VATSIM.net webhook processing pipeline to make action handling deterministic (timestamp ordering + chained dispatch), improve observability, and reduce duplicated delta parsing logic across webhook jobs.
Changes:
- Refactored
ProcessVatsimNetWebhookto sort actions deterministically, resolve jobs via a map, and dispatch viaBus::chain()with structured logging. - Introduced
InteractsWithMemberDeltastrait and updatedMemberCreatedAction/MemberChangedActionto use cached delta parsing helpers. - Added a feature test asserting unknown webhook actions return
400 Bad Request.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
app/Http/Controllers/External/VatsimNet/ProcessVatsimNetWebhook.php |
Centralizes action→job resolution, sorts actions by timestamp, chains jobs, and improves logging/empty-payload handling. |
app/Jobs/ExternalServices/VatsimNet/Webhooks/Concerns/InteractsWithMemberDeltas.php |
Adds reusable cached delta parsing + changed-field map helpers. |
app/Jobs/ExternalServices/VatsimNet/Webhooks/MemberCreatedAction.php |
Simplifies creation handling using the delta trait and adds debug logging. |
app/Jobs/ExternalServices/VatsimNet/Webhooks/MemberChangedAction.php |
Refactors update handling into focused methods using the delta trait and adds debug logging. |
tests/Feature/External/Webhooks/WebhooksTest.php |
Adds coverage for unknown webhook action returning 400. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
|
See issue comment |
Refs #4550
This PR further refactors the VATSIM.net webhook pipeline to improve determinism, performance, logging, and internal structure while preserving existing behaviour.
🚀 Controller Improvements (
ProcessVatsimNetWebhook)✅ Deterministic Ordering
collect()->sortBy('timestamp')->values()to guarantee correct execution order.Bus::chain()to prevent race conditions between actions.🗺️ Centralised Action Resolution
ACTION_JOB_MAPconstant to replace theswitchstatement.createActionJob()resolver method.400 Bad RequestThis makes the system easier to extend with additional webhook actions.
📊 Improved Logging & Observability
resourceactions.lengthactions.typespreparation_ms) for lightweight performance insight.🧯 Graceful Empty Payload Handling
200 OK🔐 Security
validateAuth()now strictly typed (: void)🧩 New Trait:
InteractsWithMemberDeltasIntroduced reusable delta handling logic:
Features
getDeltaAfter(field)helperchangedFields()keyed map offield => afterThis removes duplicated delta parsing logic and reduces repeated collection operations.
👤
MemberChangedActionRefactorStructural Changes
InteractsWithMemberDeltastraitACCOUNT_FIELDSconstantprocessAccountChanges()processRatingChanges()processStateChange()Behaviour Improvements
Benefits
👶
MemberCreatedActionRefactorupdateOrCreatelogicresourceandaccount_idImproves readability and consistency with the update handler.
🧪 Test Coverage Improvements
Added:
test_unknown_action_returns_bad_request()to ensure invalid webhook actions return400.Existing tests validate:
🧼 Overall Outcome
This refactor delivers:
The webhook pipeline is now more maintainable, extensible, and production-observable while preserving existing functionality.