Skip to content

Refactor audits, certificates, and screenshots queues to publishers#11851

Merged
ChiragAgg5k merged 13 commits into1.9.xfrom
chore-migrate-audits-certificates-screenshots-to-publishers
Apr 15, 2026
Merged

Refactor audits, certificates, and screenshots queues to publishers#11851
ChiragAgg5k merged 13 commits into1.9.xfrom
chore-migrate-audits-certificates-screenshots-to-publishers

Conversation

@ChiragAgg5k
Copy link
Copy Markdown
Member

What does this PR do?

Migrates the next queue resource slice from mutable queueForX resources to typed publisherForX resources for audits, certificates, and screenshots.

This adds strongly typed DTOs and publishers for each queue, replaces audit request-state mutation with a dedicated auditContext, updates the affected producers and workers to publish typed messages, and switches the related health endpoints to read queue size through the new publishers.

Test Plan

  • composer format on all touched PHP files
  • composer lint on all touched PHP files
  • php -l on all touched PHP files
  • git diff --check
  • rg -n "queueFor(Audits|Certificates|Screenshots)" app src

Related PRs and Issues

Checklist

  • Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs?

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 10, 2026

Greptile Summary

This PR continues the publisher-pattern migration by replacing queueForAudits, queueForCertificates, and queueForScreenshots with typed DTOs and dedicated publisher classes, and introduces AuditContext as a request-scoped mutable state object that decouples audit data collection from queue dispatch. The refactoring is consistent and complete — all producers, workers, health endpoints, and task runners are updated, and rg -n "queueFor(Audits|Certificates|Screenshots)" returns no results.

Confidence Score: 5/5

Safe to merge — the migration is complete, all queue references are updated, and no P0/P1 issues were found.

All legacy queueForAudits, queueForCertificates, and queueForScreenshots references have been removed. The shutdown-hook audit logic is preserved with a more defensive null-check. Worker field access is correctly rewritten to typed DTOs. The only finding is P2 (an unused isEmpty() method on AuditContext).

No files require special attention.

Important Files Changed

Filename Overview
src/Appwrite/Event/Context/Audit.php New request-scoped DTO replacing mutable Audit event object; clean design with nullable fields and an isEmpty() helper that is currently unused
src/Appwrite/Event/Message/Audit.php New typed message DTO; fromContext factory covers all fields from the old Audit::preparePayload(), fromArray round-trips cleanly
src/Appwrite/Event/Message/Certificate.php New typed Certificate message DTO; faithfully mirrors old Certificate::preparePayload() and fromArray round-trips correctly
src/Appwrite/Event/Message/Screenshot.php New typed Screenshot message DTO; drops the unused platform field from the old queue object, keeping only project and deploymentId
src/Appwrite/Event/Publisher/Audit.php New typed Audit publisher with best-effort delivery (catches Throwable and logs, doesn't fail the request lifecycle); consistent with the audit queue's non-critical semantics
app/controllers/shared/api.php Replaces queueForAudits DI resource with auditContext + publisherForAudits; shutdown hook logic preserved including the null-guard on auditContext->user (now more defensive than the old getUser()->isEmpty() call)
src/Appwrite/Platform/Workers/Audits.php Drops DI-injected project in favour of $auditMessage->project from message payload; all fields the worker needs ($id, $sequence, database) are present in the serialized project
src/Appwrite/Platform/Workers/Certificates.php Clean migration to typed message DTO; $certificateMessage->project is embedded but not consumed (same as old behaviour), all other fields correctly propagated
app/init/resources.php Registers publisherForAudits, publisherForCertificates, and publisherForScreenshots; publisherForCertificates is also registered in cli.php (a duplicate already flagged in a prior thread)
app/init/resources/request.php Removes queueForAudits, queueForCertificates, queueForScreenshots; registers auditContext following the same factory pattern as usage (safe for Swoole coroutine isolation)
src/Appwrite/Platform/Modules/Functions/Workers/Builds.php Injects publisherForScreenshots and enqueues a typed Screenshot message after successful site build; correct
src/Appwrite/Platform/Tasks/Maintenance.php Migrates renewCertificates to typed publisher; now explicitly builds sparse project Document from rule attributes where old code left project as null
src/Appwrite/Platform/Modules/Health/Http/Health/Queue/Failed/Get.php Replaces three legacy Event subclasses with typed publishers in the queue-size match statement; duck-typed getSize(failed: true) call still works since all objects expose the method

Reviews (11): Last reviewed commit: "Merge branch '1.9.x' into chore-migrate-..." | Re-trigger Greptile

Comment thread src/Appwrite/Event/Message/Screenshot.php
Comment thread app/cli.php
@ChiragAgg5k ChiragAgg5k force-pushed the chore-migrate-audits-certificates-screenshots-to-publishers branch from b4eb8cb to 0de26be Compare April 10, 2026 11:15
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 10, 2026

🔄 PHP-Retry Summary

Flaky tests detected across commits:

Commit a31cb67 - 5 flaky tests
Test Retries Total Time Details
UsageTest::testFunctionsStats 1 10.23s Logs
UsageTest::testPrepareSitesStats 1 6ms Logs
UsageTest::testEmbeddingsTextUsageDoesNotBreakProjectUsage 1 5ms Logs
LegacyCustomClientTest::testAttributeResponseModels 1 241.77s Logs
LegacyCustomServerTest::testAttributeResponseModels 1 242.43s Logs
Commit 86cfea0 - 5 flaky tests
Test Retries Total Time Details
UsageTest::testFunctionsStats 1 10.22s Logs
UsageTest::testPrepareSitesStats 1 7ms Logs
UsageTest::testEmbeddingsTextUsageDoesNotBreakProjectUsage 1 5ms Logs
TablesDBTransactionsCustomClientTest::testUpsertAutoIdThenUpdate 1 240.56s Logs
TablesDBTransactionsCustomServerTest::testBulkDeleteOperations 1 240.55s Logs
Commit 5d53685 - 5 flaky tests
Test Retries Total Time Details
UsageTest::testFunctionsStats 1 10.23s Logs
UsageTest::testPrepareSitesStats 1 7ms Logs
UsageTest::testEmbeddingsTextUsageDoesNotBreakProjectUsage 1 5ms Logs
TablesDBConsoleClientTest::testTimeout 1 240.41s Logs
TablesDBCustomClientTest::testEnforceCollectionPermissions 1 240.46s Logs
Commit b2884dd - 7 flaky tests
Test Retries Total Time Details
UsageTest::testFunctionsStats 1 10.24s Logs
UsageTest::testPrepareSitesStats 1 7ms Logs
UsageTest::testEmbeddingsTextUsageDoesNotBreakProjectUsage 1 5ms Logs
LegacyConsoleClientTest::testListDocumentsWithCache 1 1.09s Logs
LegacyConsoleClientTest::testListDocumentsCachePurgedByUpdate 1 1.63s Logs
LegacyCustomClientTest::testAttributeResponseModels 1 241.07s Logs
LegacyTransactionsCustomServerTest::testOperationsOnNonExistentDocuments 1 240.18s Logs
Commit 29be9b6 - 5 flaky tests
Test Retries Total Time Details
UsageTest::testFunctionsStats 1 10.26s Logs
UsageTest::testPrepareSitesStats 1 9ms Logs
UsageTest::testEmbeddingsTextUsageDoesNotBreakProjectUsage 1 8ms Logs
TablesDBCustomClientTest::testEnforceCollectionAndDocumentPermissions 1 86ms Logs
TablesDBCustomClientTest::testNotContains 1 240.54s Logs

Note: Flaky test results are tracked for the last 5 commits

@blacksmith-sh

This comment has been minimized.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 10, 2026

✨ Benchmark results

  • Requests per second: 1,799
  • Requests with 200 status code: 323,828
  • P99 latency: 0.098562372

⚡ Benchmark Comparison

Metric This PR Latest version
RPS 1,799 1,382
200 323,828 248,728
P99 0.098562372 0.1468687

@blacksmith-sh

This comment has been minimized.

@ChiragAgg5k ChiragAgg5k merged commit 49c93c6 into 1.9.x Apr 15, 2026
80 of 81 checks passed
@ChiragAgg5k ChiragAgg5k deleted the chore-migrate-audits-certificates-screenshots-to-publishers branch April 15, 2026 09:43
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