Skip to content

refactor use env variables for queue and class names#11010

Merged
ChiragAgg5k merged 2 commits into1.8.xfrom
update-schedule-functions
Dec 23, 2025
Merged

refactor use env variables for queue and class names#11010
ChiragAgg5k merged 2 commits into1.8.xfrom
update-schedule-functions

Conversation

@ChiragAgg5k
Copy link
Copy Markdown
Member

No description provided.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Dec 23, 2025

Warning

Rate limit exceeded

@ChiragAgg5k has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 14 minutes and 22 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 53965a6 and bbeca28.

📒 Files selected for processing (13)
  • app/controllers/api/health.php
  • src/Appwrite/Event/Audit.php
  • src/Appwrite/Event/Build.php
  • src/Appwrite/Event/Certificate.php
  • src/Appwrite/Event/Database.php
  • src/Appwrite/Event/Delete.php
  • src/Appwrite/Event/Func.php
  • src/Appwrite/Event/Mail.php
  • src/Appwrite/Event/Messaging.php
  • src/Appwrite/Event/Migration.php
  • src/Appwrite/Event/StatsResources.php
  • src/Appwrite/Event/StatsUsage.php
  • src/Appwrite/Event/Webhook.php
📝 Walkthrough

Walkthrough

This pull request migrates queue name and worker class name configuration from hardcoded constants in the Event class to environment-driven lookups. New global constants are introduced in app/init/constants.php for all queue names and corresponding worker class names. All Event subclasses (Audit, Build, Certificate, Database, Delete, Func, Mail, Messaging, Migration, StatsResources, StatsUsage, Webhook) are updated to resolve queue and class names via System::getEnv() with fallbacks to the new global constants, replacing previous direct references to Event class constants. The Event class itself has those constants removed, and the health endpoint is updated to accommodate these changes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Description check ❓ Inconclusive No pull request description was provided by the author, so the check cannot evaluate relatedness. Add a description explaining the motivation, changes, and any relevant context for this refactoring (e.g., why environment variables are needed).
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: refactoring queue and class name configuration to use environment variables instead of static constants.

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.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Dec 23, 2025

Security Scan Results for PR

Docker Image Scan Results

Package Version Vulnerability Severity
libpng 1.6.51-r0 CVE-2025-66293 HIGH
libpng-dev 1.6.51-r0 CVE-2025-66293 HIGH

Source Code Scan Results

🎉 No vulnerabilities found!

Copy link
Copy Markdown
Contributor

@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: 0

Caution

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

⚠️ Outside diff range comments (1)
src/Appwrite/Platform/Tasks/ScheduleFunctions.php (1)

44-44: Address the TODO: $lastEnqueueUpdate is never updated, breaking enqueue timing logic.

The property $lastEnqueueUpdate is read on line 44 to calculate $enqueueDiff, but it's never updated (line 116 is commented out). Since the property remains null forever, $enqueueDiff is always 0, and the timeframe calculation on line 45 always uses the full ENQUEUE_TIMER value (60 seconds).

The TODO comment indicates this was intentionally disabled because updating it breaks scheduling, but this leaves the enqueue timing logic in a broken state. The mention of "wasn't passed by reference" suggests a deeper architectural issue.

Please either:

  • Fix the underlying architectural issue so $lastEnqueueUpdate can be properly updated, or
  • Remove the unused property and simplify the logic if dynamic timing is not needed
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 309fde3 and 64b69a4.

📒 Files selected for processing (1)
  • src/Appwrite/Platform/Tasks/ScheduleFunctions.php
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: scan-pr / osv-scan
  • GitHub Check: Setup & Build Appwrite Image
  • GitHub Check: Setup & Build Appwrite Image
  • GitHub Check: scan
🔇 Additional comments (1)
src/Appwrite/Platform/Tasks/ScheduleFunctions.php (1)

22-22: Remove unnecessary protected visibility or add subclass access justification.

No subclasses of ScheduleFunctions were found in the codebase. The $lastEnqueueUpdate property is only used within this class and never accessed from any subclass. If this visibility change is not needed for subclass access, consider reverting it to private.

Additionally, note that the property update on line 116 remains commented out with a TODO stating it "breaks scheduling", leaving $lastEnqueueUpdate permanently null and making the enqueue diff calculation on line 44 always zero.

Likely an incorrect or invalid review comment.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Dec 23, 2025

✨ Benchmark results

  • Requests per second: 1,162
  • Requests with 200 status code: 209,257
  • P99 latency: 0.167166348

⚡ Benchmark Comparison

Metric This PR Latest version
RPS 1,162 1,245
200 209,257 224,066
P99 0.167166348 0.164539921

@ChiragAgg5k ChiragAgg5k force-pushed the update-schedule-functions branch from 64b69a4 to 9ab9f6d Compare December 23, 2025 09:36
Copy link
Copy Markdown
Contributor

@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: 0

🧹 Nitpick comments (1)
src/Appwrite/Platform/Tasks/ScheduleFunctions.php (1)

119-120: Address the TODO comment for lastEnqueueUpdate bug.

The TODO indicates a known bug where updating $lastEnqueueUpdate breaks scheduling. While this PR doesn't address this issue, the technical debt should be tracked and investigated separately to ensure proper timing behavior.

Would you like me to open a separate issue to track this bug? Understanding and resolving this timing issue would improve the reliability of the scheduling mechanism.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 64b69a4 and 9ab9f6d.

📒 Files selected for processing (1)
  • src/Appwrite/Platform/Tasks/ScheduleFunctions.php
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-08-22T06:23:32.026Z
Learnt from: ItzNotABug
Repo: appwrite/appwrite PR: 10348
File: app/controllers/shared/api.php:546-546
Timestamp: 2025-08-22T06:23:32.026Z
Learning: In the Utopia Queue system, the Pool class implements both Publisher and Consumer interfaces, so BrokerPool (Pool) can be passed directly to constructors expecting Publisher parameters like Func::__construct(protected Publisher $publisher).

Applied to files:

  • src/Appwrite/Platform/Tasks/ScheduleFunctions.php
🧬 Code graph analysis (1)
src/Appwrite/Platform/Tasks/ScheduleFunctions.php (1)
src/Appwrite/Event/Func.php (1)
  • Func (9-229)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: scan-pr / osv-scan
  • GitHub Check: Setup & Build Appwrite Image
  • GitHub Check: Check if utopia-php/database changed
  • GitHub Check: scan
🔇 Additional comments (3)
src/Appwrite/Platform/Tasks/ScheduleFunctions.php (3)

39-42: Excellent use of factory method pattern.

The getQueueForFunctions() method centralizes queue instantiation, making the code more maintainable and testable. The protected visibility enables subclasses to customize queue creation behavior if needed.


103-103: Inconsistency found: ScheduleExecutions.php should also use the factory method.

The factory method usage in line 103 is correct. However, the codebase shows an inconsistency: src/Appwrite/Platform/Tasks/ScheduleExecutions.php:39 directly instantiates Func with the same pattern instead of using a factory method like ScheduleFunctions.php does. For consistency across similar task classes, ScheduleExecutions.php should be refactored to use a corresponding factory method.


22-22: Remove the incorrect reasoning about $lastEnqueueUpdate visibility.

The factory method pattern (getQueueForFunctions()) is valid for extensibility, but the visibility change of $lastEnqueueUpdate from private to protected is not justified by this pattern. The property is only used internally at line 49 within enqueueResources(), and there are no subclasses in the codebase that would benefit from accessing it. The visibility change appears speculative without evidence of actual subclass usage.

@ChiragAgg5k ChiragAgg5k changed the title chore: update schedule functions task refactor use env variables for queue and class names Dec 23, 2025
Copy link
Copy Markdown
Contributor

@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: 0

🧹 Nitpick comments (2)
app/controllers/api/health.php (1)

948-959: Consider caching environment lookups to avoid duplication.

The System::getEnv() calls are duplicated in both the WhiteList validator (lines 948-959) and the match expression (lines 996-1007). While this works correctly, it introduces maintenance overhead and potential for drift if one is updated but not the other.

🔎 Proposed refactor to reduce duplication

Consider extracting queue name resolution to local variables or a helper, for example at the start of the action closure:

$queueNames = [
    'database' => System::getEnv('_APP_DATABASE_QUEUE_NAME', APP_DATABASE_QUEUE_NAME),
    'delete' => System::getEnv('_APP_DELETE_QUEUE_NAME', APP_DELETE_QUEUE_NAME),
    // ... other queues
];

$queue = match ($name) {
    $queueNames['database'] => $queueForDatabase,
    $queueNames['delete'] => $queueForDeletes,
    // ...
};

Also applies to: 996-1007

src/Appwrite/Event/Event.php (1)

9-9: Unused import.

The System class is imported but doesn't appear to be used in this file. The System::getEnv() calls are made in the subclasses, not in the base Event class.

🔎 Proposed fix
-use Utopia\System\System;
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9ab9f6d and 53965a6.

📒 Files selected for processing (15)
  • app/controllers/api/health.php
  • app/init/constants.php
  • src/Appwrite/Event/Audit.php
  • src/Appwrite/Event/Build.php
  • src/Appwrite/Event/Certificate.php
  • src/Appwrite/Event/Database.php
  • src/Appwrite/Event/Delete.php
  • src/Appwrite/Event/Event.php
  • src/Appwrite/Event/Func.php
  • src/Appwrite/Event/Mail.php
  • src/Appwrite/Event/Messaging.php
  • src/Appwrite/Event/Migration.php
  • src/Appwrite/Event/StatsResources.php
  • src/Appwrite/Event/StatsUsage.php
  • src/Appwrite/Event/Webhook.php
🧰 Additional context used
🧠 Learnings (3)
📚 Learning: 2025-08-22T06:23:32.026Z
Learnt from: ItzNotABug
Repo: appwrite/appwrite PR: 10348
File: app/controllers/shared/api.php:546-546
Timestamp: 2025-08-22T06:23:32.026Z
Learning: In the Utopia Queue system, the Pool class implements both Publisher and Consumer interfaces, so BrokerPool (Pool) can be passed directly to constructors expecting Publisher parameters like Func::__construct(protected Publisher $publisher).

Applied to files:

  • src/Appwrite/Event/StatsResources.php
  • src/Appwrite/Event/Func.php
  • src/Appwrite/Event/Webhook.php
  • src/Appwrite/Event/Messaging.php
  • src/Appwrite/Event/Build.php
  • src/Appwrite/Event/Delete.php
  • src/Appwrite/Event/Mail.php
  • src/Appwrite/Event/StatsUsage.php
  • src/Appwrite/Event/Migration.php
  • src/Appwrite/Event/Certificate.php
  • src/Appwrite/Event/Event.php
📚 Learning: 2025-08-22T06:23:32.026Z
Learnt from: ItzNotABug
Repo: appwrite/appwrite PR: 10348
File: app/controllers/shared/api.php:546-546
Timestamp: 2025-08-22T06:23:32.026Z
Learning: The Utopia\Queue\Broker\Pool class (aliased as BrokerPool) implements both Publisher and Consumer interfaces, making it directly compatible with constructors expecting Publisher parameters like Func::__construct(protected Publisher $publisher). No wrapping is needed.

Applied to files:

  • src/Appwrite/Event/StatsResources.php
  • src/Appwrite/Event/Func.php
  • src/Appwrite/Event/Webhook.php
  • src/Appwrite/Event/Messaging.php
  • src/Appwrite/Event/Build.php
  • src/Appwrite/Event/Delete.php
  • src/Appwrite/Event/StatsUsage.php
  • src/Appwrite/Event/Migration.php
  • src/Appwrite/Event/Certificate.php
📚 Learning: 2025-11-12T04:07:12.576Z
Learnt from: abnegate
Repo: appwrite/appwrite PR: 10800
File: src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Delete.php:153-154
Timestamp: 2025-11-12T04:07:12.576Z
Learning: In Appwrite's event queue system, `queueForRealtime`, `queueForFunctions`, and `queueForWebhooks` are copied from `queueForEvents`. Therefore, when resetting event queues in transaction staging paths, only `$queueForEvents->reset()` needs to be called in most cases. The other queues only require explicit reset when they are triggered in a loop.

Applied to files:

  • src/Appwrite/Event/Func.php
  • app/controllers/api/health.php
🧬 Code graph analysis (12)
src/Appwrite/Event/Audit.php (1)
src/Appwrite/Event/Event.php (2)
  • setQueue (62-67)
  • setClass (247-252)
src/Appwrite/Event/StatsResources.php (1)
src/Appwrite/Event/Event.php (2)
  • setQueue (62-67)
  • setClass (247-252)
src/Appwrite/Event/Func.php (1)
src/Appwrite/Event/Event.php (2)
  • setQueue (62-67)
  • setClass (247-252)
src/Appwrite/Event/Webhook.php (1)
src/Appwrite/Event/Event.php (2)
  • setQueue (62-67)
  • setClass (247-252)
src/Appwrite/Event/Messaging.php (1)
src/Appwrite/Event/Event.php (2)
  • setQueue (62-67)
  • setClass (247-252)
src/Appwrite/Event/Build.php (1)
src/Appwrite/Event/Event.php (2)
  • setQueue (62-67)
  • setClass (247-252)
src/Appwrite/Event/Delete.php (1)
src/Appwrite/Event/Event.php (2)
  • setQueue (62-67)
  • setClass (247-252)
src/Appwrite/Event/Mail.php (1)
src/Appwrite/Event/Event.php (2)
  • setQueue (62-67)
  • setClass (247-252)
src/Appwrite/Event/StatsUsage.php (1)
src/Appwrite/Event/Event.php (2)
  • setQueue (62-67)
  • setClass (247-252)
src/Appwrite/Event/Database.php (1)
src/Appwrite/Event/Event.php (1)
  • setClass (247-252)
src/Appwrite/Event/Migration.php (1)
src/Appwrite/Event/Event.php (2)
  • setQueue (62-67)
  • setClass (247-252)
src/Appwrite/Event/Certificate.php (1)
src/Appwrite/Event/Event.php (2)
  • setQueue (62-67)
  • setClass (247-252)
🔇 Additional comments (14)
app/controllers/api/health.php (1)

1009-1015: LGTM!

The failed jobs handling logic is clear and the variable naming ($failed) accurately reflects the data being tracked.

app/init/constants.php (1)

378-404: LGTM!

The new constants are well-organized, consistently named, and follow the established patterns. All 12 services have matching queue and class name constants.

src/Appwrite/Event/Mail.php (1)

23-30: LGTM!

The environment-driven configuration is correctly implemented with proper fallback to constants, ensuring backward compatibility.

src/Appwrite/Event/Messaging.php (1)

18-25: LGTM!

The environment-driven configuration follows the consistent pattern established across all event classes.

src/Appwrite/Event/Webhook.php (1)

10-17: LGTM!

Consistent implementation of environment-driven configuration with proper fallbacks.

src/Appwrite/Event/Audit.php (1)

18-25: LGTM!

The environment-driven configuration is correctly implemented, maintaining consistency with other event classes.

src/Appwrite/Event/Database.php (1)

24-29: LGTM!

The Database event correctly only sets the class name via environment variable, as the queue name is dynamically determined from the project's database DSN in setProject() (lines 165-179). This is the appropriate pattern for this event type.

src/Appwrite/Event/Func.php (1)

8-8: LGTM!

The environment-driven configuration is implemented consistently with the Delete event class.

Also applies to: 29-30

src/Appwrite/Event/Build.php (1)

8-8: LGTM!

The changes follow the same environment-driven configuration pattern as other event classes.

Also applies to: 22-23

src/Appwrite/Event/Certificate.php (1)

7-7: LGTM!

Environment-based configuration is correctly implemented with appropriate fallbacks.

Also applies to: 20-21

src/Appwrite/Event/StatsUsage.php (1)

7-7: LGTM!

The configuration pattern is consistent with other event classes in this PR.

Also applies to: 22-23

src/Appwrite/Event/StatsResources.php (1)

6-6: LGTM!

The changes are consistent and follow the established pattern for environment-driven configuration.

Also applies to: 17-18

src/Appwrite/Event/Migration.php (1)

8-8: LGTM!

The migration event follows the same environment-driven pattern, completing the consistent refactor across all event classes.

Also applies to: 20-21

src/Appwrite/Event/Delete.php (1)

7-7: Environment-driven configuration with proper constant fallbacks.

The System import and configuration in the constructor correctly implement environment-based settings with fallbacks. Both APP_DELETE_QUEUE_NAME and APP_DELETE_CLASS_NAME constants are defined in app/init/constants.php, and the pattern is consistent with other event classes in the codebase.

@ChiragAgg5k ChiragAgg5k force-pushed the update-schedule-functions branch 2 times, most recently from 24f1ca2 to 43d48f1 Compare December 23, 2025 10:38
@ChiragAgg5k ChiragAgg5k force-pushed the update-schedule-functions branch from 43d48f1 to bbeca28 Compare December 23, 2025 10:39
@ChiragAgg5k ChiragAgg5k merged commit cdbd80c into 1.8.x Dec 23, 2025
102 of 104 checks passed
@ChiragAgg5k ChiragAgg5k deleted the update-schedule-functions branch December 23, 2025 11:56
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.

3 participants