Skip to content

feat(queue): add TTL retention and purge command for failed jobs - #15752

Open
Harshit-2208 wants to merge 8 commits into
appwrite:mainfrom
Harshit-2208:feat/queue-failed-ttl
Open

Harshit-2208 wants to merge 8 commits into
appwrite:mainfrom
Harshit-2208:feat/queue-failed-ttl

Conversation

@Harshit-2208

Copy link
Copy Markdown

What does this PR do?

Adds configurable TTL-based retention and manual purge capabilities for failed queue jobs in Redis to prevent unbounded memory growth over time.

Summary of Changes

  • Configurable Failed Job TTL (_APP_QUEUE_FAILED_TTL):
    • Added _APP_QUEUE_FAILED_TTL environment variable (default 604800 seconds / 7 days) in app/config/variables.php and wired it into app/worker.php via Server::setJobTtl().
    • Updated Redis::maintain() with trimFailed() to periodically sweep orphaned PIDs from utopia-queue.failed.<queue> once their Redis payload keys expire.
  • CLI Purge & Retry Enhancements:
    • Added queue-purge CLI task (QueuePurge + bin/queue-purge) supporting --name, --older-than (in days), and --limit to delete failed job entries and their payloads without affecting active jobs.
    • Added --newer-than (in seconds) to queue-retry (QueueRetry) so operators can selectively re-drive recent failures.
    • Extended Publisher\Synchronous with purge() and $newerThan on retry(), updating Redis, Pool, Background, Nats, and MockPublisher.
    • Removed the broken bin/queue-count-failed wrapper script referencing a non-existent queue-count task.

Test Plan

  • Verified PHP syntax (php -l) across all modified and added files.
  • Verified CLI flags and input validation for queue-purge and queue-retry --newer-than.

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?

@appwrite

appwrite Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Code review

Commit Status Tier Verdict Details
071029a Reviewed Reviewed 🟢 S · Ready to merge 💬 Commented View review

The previously reported issues are addressed, and the incremental changes introduce no remaining defects.

This PR adds configurable TTL retention for failed Redis queue payloads, trims expired failed-list entries during maintenance, and adds queue-purge with age and count filters. It also adds a newer-than filter to queue-retry, extends the synchronous publisher contract and broker implementations, and updates CLI registration and wrappers.

Latest changes: The latest commits replace the stale Docker chmod entry, make unsupported NATS purges fail explicitly, allow unfiltered Redis purges to remove corrupt payloads, and add Redis purge regression tests and the remaining publisher test-double implementations.

Note

@Harshit-2208 does not have write access to this repository, so Hansi does not approve automatically. A maintainer can review and approve.

Walkthrough (20)
File Change
Dockerfile Changes the executable chmod entry from the removed failed-count wrapper to queue-purge.
app/config/variables.php Adds the configurable failed-job TTL setting.
app/worker.php Passes the configured failed-job TTL to the queue server.
bin/queue-count-failed Removes the obsolete failed-count wrapper.
bin/queue-purge Adds the queue-purge CLI entry point.
packages/queue/src/Broker/Background.php Forwards retry age filters and purge calls to the underlying publisher.
packages/queue/src/Broker/Nats.php Extends retry arguments and reports that purge is unsupported by NATS.
packages/queue/src/Broker/Pool.php Forwards the updated retry arguments and purge calls through the pool.
packages/queue/src/Broker/Redis.php Adds failed-list trimming, retry age filtering, and failed-job purge behavior.
packages/queue/src/Publisher/Synchronous.php Extends the synchronous publisher contract with retry age filtering and purge.
packages/queue/src/Server.php Adds server-level job TTL configuration for registered queues.
packages/queue/tests/BackgroundTest.php Updates background publisher test doubles for the expanded interface.
packages/queue/tests/RedisPurgeTest.php Adds tests for Redis purge selection, limits, corrupt or missing payloads, and maintenance trimming.
packages/queue/tests/ServerTelemetryTest.php Updates telemetry publisher test doubles for the expanded interface.
src/Appwrite/Platform/Services/Tasks.php Registers the queue-purge CLI task.
src/Appwrite/Platform/Tasks/QueuePurge.php Adds CLI arguments, validation, and invocation for failed-job purging.
src/Appwrite/Platform/Tasks/QueueRetry.php Adds validation and forwarding for the retry newer-than filter.
tests/unit/Event/MockPublisher.php Updates the mock publisher for the expanded synchronous publisher contract.
tests/unit/Maintenance/QueuePublisher.php Updates the maintenance queue publisher test double for the expanded contract.
tests/unit/Usage/CapturingPublisher.php Updates the usage publisher test double for the expanded contract.

Merged main (8d9c1fc); no changes to this PR's code since 071029a

Tip

Comment @appwrite review to re-run, or mention @appwrite with a question.

@appwrite appwrite Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Tier B · See the inline comments. Summary

Comment thread bin/queue-purge Resolved
appwrite[bot]
appwrite Bot previously requested changes Nov 17, 2026

@appwrite appwrite Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Tier B · 1 blocking finding to address. Summary

Comment thread bin/queue-purge Resolved
Comment thread packages/queue/src/Broker/Redis.php Resolved
Comment thread packages/queue/src/Broker/Nats.php Resolved
Comment thread packages/queue/src/Broker/Redis.php Resolved

@appwrite appwrite Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Tier S · Looks good to merge. Summary

@appwrite
appwrite Bot dismissed their stale review November 18, 2026 00:07

The findings that requested changes are resolved. See the summary comment for what is still open.

This branch has not been deployed

No deployments
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.

🐛 Bug Report: Failed queue jobs never expire and there is no way to purge them

1 participant