Repository navigation
Conversation
|
| $locks('jobs-deployment:' . $deploymentId, self::LOCK_TTL, function () use ($dbForProject, $dbForPlatform, $project, $deploymentId, $size, $logs, $publisherForScreenshots, $vcsFactory, $platform, $bus, $usage, $publisherForUsage, $queueForRealtime, $queueForEvents, $queueForWebhooks, $publisherForFunctions): void { | ||
| $deployment = $dbForProject->getDocument('deployments', $deploymentId); | ||
| if ($deployment->isEmpty() || $deployment->getAttribute('status') === 'canceled') { | ||
| if ($deployment->isEmpty() || \in_array($deployment->getAttribute('status'), ['ready', 'failed', 'canceled'], true)) { | ||
| return; | ||
| } | ||
|
|
||
| $statusBefore = $deployment->getAttribute('status'); | ||
| $durationBefore = $deployment->getAttribute('buildDuration'); | ||
| $deployment->setAttribute('buildLogs', $deployment->getAttribute('buildLogs', '') . $logs); | ||
| $deployment = $this->finalize($dbForProject, $dbForPlatform, $project, $deployment, true, '', $publisherForScreenshots, $vcsFactory, $platform, $bus, $size); | ||
| $this->publishUpdate($dbForProject, $project, $deployment, $statusBefore, $durationBefore, $usage, $publisherForUsage, $queueForRealtime, $queueForEvents, $queueForWebhooks, $publisherForFunctions); | ||
| }, self::LOCK_TIMEOUT); |
There was a problem hiding this comment.
This new two-lock finalization flow has no CE worker-level coverage. Existing Jobs tests only check queue configuration, so regressions involving cancellation during beforeFinalize(), callback redelivery after a hook or lock failure, competing terminal callbacks, or logs written between locks could go unnoticed. Please add observable-behavior tests that coordinate these cases and verify the durable deployment state and one-time side effects rather than mirroring the implementation phases.
Knowledge Base Used:
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Appwrite/Platform/Modules/Functions/Workers/Jobs.php
Line: 166-177
Comment:
**Missing Concurrency Coverage**
This new two-lock finalization flow has no CE worker-level coverage. Existing Jobs tests only check queue configuration, so regressions involving cancellation during `beforeFinalize()`, callback redelivery after a hook or lock failure, competing terminal callbacks, or logs written between locks could go unnoticed. Please add observable-behavior tests that coordinate these cases and verify the durable deployment state and one-time side effects rather than mirroring the implementation phases.
**Knowledge Base Used:**
- [Functions and execution processing](https://app.greptile.com/appwrite/-/custom-context/knowledge-base/appwrite/appwrite/-/docs/functions-execution-api.md)
- [Worker job families](https://app.greptile.com/appwrite/-/custom-context/knowledge-base/appwrite/appwrite/-/docs/worker-job-families.md)
- [Background processing and scheduling](https://app.greptile.com/appwrite/-/custom-context/knowledge-base/appwrite/appwrite/-/docs/background-processing.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
What does this PR do?
Split successful build finalization into three phases in the same queue job: apply callbacks and validate under the deployment lock, run an idempotent
beforeFinalize()hook outside the lock, then reacquire the lock and finalize from a fresh deployment record. The queue job returns only after finalization. Cancellation or another callback's terminal outcome wins when the lock is reacquired.Cloud uses the hook for edge distribution. Production edge calls took 74–82 seconds while the deployment lock lease is 30 seconds. Moving that wait outside the lock avoids holding an expired lease or blocking log callbacks. The hook returns progress logs, which are appended to the latest record under the finalization lock.
Replace the unused deferred-callback hooks with this single hook. Replaying an already-applied terminal callback still attempts readiness, so a failed hook or second lock acquisition can be retried without another queue protocol. Usage, realtime, and terminal notifications stay under the lock. Production code decreases by 18 lines.
Cloud companion: https://github.com/appwrite-labs/cloud/pull/5836 (replaces its initial queued-event approach). Production investigation.
Test Plan
Validated through Cloud's registered worker callback using this CE source:
No Kubernetes/edge E2E or staging drill has been run. Tests for the Cloud extension are in the companion PR; this PR adds no worker unit tests to CE. Stage both PRs together, exercise a slow site distribution plus cancellation and callback redelivery, and check stored logs, terminal status and usage. Existing Redis failed-job recovery still controls when failed messages are retried.
Checklist