chore(audits): return queue pre-fetch results#9731
Conversation
WalkthroughThe batch processing logic in the Audits worker was refactored to dynamically determine batch size from an environment variable, update type declarations, and refine control flow. The action method now returns result objects based on whether a batch was processed, and batch processing is triggered by the total log count rather than project count. Changes
Sequence Diagram(s)sequenceDiagram
participant Worker as Audits Worker
participant Env as Environment
participant ProjectDB as Project Database
participant Logger as Logger
Worker->>Env: Get _APP_QUEUE_PREFETCH_COUNT
Env-->>Worker: Return batch size
Worker->>Worker: Count total logs across projects
alt Batch should be processed
loop For each project with logs
Worker->>ProjectDB: getProjectDB(project)
Worker->>ProjectDB: Log batch
alt Error occurs
Worker->>Logger: Log error
end
end
Worker->>Worker: Update last triggered time
Worker-->>Caller: Return Commit
else Batch not processed
Worker-->>Caller: Return NoCommit
end
Poem
📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (11)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
Security Scan Results for PRDocker Image Scan Results
Source Code Scan Results🎉 No vulnerabilities found! |
✨ Benchmark results
⚡ Benchmark Comparison
|
0174614 to
1f346f5
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/Appwrite/Platform/Workers/Audits.php(4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: Setup & Build Appwrite Image
- GitHub Check: Setup & Build Appwrite Image
- GitHub Check: scan
🔇 Additional comments (7)
src/Appwrite/Platform/Workers/Audits.php (7)
15-16: LGTM: Import statements for new result types.The new imports for
CommitandNoCommitare correctly added to support the updated return type of the action method.
21-21: LGTM: Explicit type declaration for constant.Adding explicit
inttyping to the constant improves code clarity and type safety.
30-30: LGTM: Safe environment variable parsing.Using
intval()ensures the environment variable is properly cast to an integer, providing better type safety and handling of invalid values.
58-58: LGTM: Updated return type matches new implementation.The return type change from
voidtoCommit|NoCommitcorrectly reflects the new behavior where the method returns result objects based on processing decisions.Also applies to: 64-64
125-132: LGTM: Improved early return logic.The new early return pattern with
NoCommitis a good optimization that avoids unnecessary processing when the batch criteria aren't met.
134-148: Consider the error handling strategy.The try-catch block correctly logs errors but continues processing and updates the trigger time even when errors occur. This might mask issues but prevents the worker from getting stuck.
Please verify this is the intended behavior - should the
lastTriggeredTimebe updated even when processing fails? This could potentially lead to lost audit logs if errors persist.
149-150: LGTM: Proper result object return.Returning
Commitafter successful processing follows the expected pattern for queue result handling.
Summary by CodeRabbit