fix: disable execution document writes for nyc region

Temporarily skip all execution createDocument and updateDocument calls
in the Functions worker when _APP_REGION is set to 'nyc' to reduce
database load. Marked with TODO comments for removal.
This commit is contained in:
Chirag Aggarwal
2026-02-07 21:19:00 +05:30
parent 9c03c5fab3
commit a520a67da8
+26 -16
View File
@@ -80,7 +80,9 @@ class Functions extends Action
// Short-term solution to offhand write operation from API container
if ($type === Func::TYPE_ASYNC_WRITE) {
$execution = new Document($payload['execution'] ?? []);
$dbForProject->createDocument('executions', $execution);
if (System::getEnv('_APP_REGION') !== 'nyc') { // TODO: Remove region check
$dbForProject->createDocument('executions', $execution);
}
return;
}
@@ -309,10 +311,12 @@ class Functions extends Action
'duration' => 0.0,
]);
$execution = $dbForProject->createDocument('executions', $execution);
if (System::getEnv('_APP_REGION') !== 'nyc') { // TODO: Remove region check
$execution = $dbForProject->createDocument('executions', $execution);
if ($execution->isEmpty()) {
throw new Exception('Failed to create execution');
if ($execution->isEmpty()) {
throw new Exception('Failed to create execution');
}
}
}
@@ -451,22 +455,26 @@ class Functions extends Action
'duration' => 0.0,
]);
$execution = $dbForProject->createDocument('executions', $execution);
if (System::getEnv('_APP_REGION') !== 'nyc') { // TODO: Remove region check
$execution = $dbForProject->createDocument('executions', $execution);
// TODO: @Meldiron Trigger executions.create event here
// TODO: @Meldiron Trigger executions.create event here
if ($execution->isEmpty()) {
throw new Exception('Failed to create or read execution');
if ($execution->isEmpty()) {
throw new Exception('Failed to create or read execution');
}
}
}
if ($execution->getAttribute('status') !== 'processing') {
$execution->setAttribute('status', 'processing');
try {
$execution = $dbForProject->updateDocument('executions', $executionId, $execution);
} catch (\Throwable $e) {
$log->addExtra('updateError', $e->getMessage());
if (System::getEnv('_APP_REGION') !== 'nyc') { // TODO: Remove region check
try {
$execution = $dbForProject->updateDocument('executions', $executionId, $execution);
} catch (\Throwable $e) {
$log->addExtra('updateError', $e->getMessage());
}
}
}
@@ -611,10 +619,12 @@ class Functions extends Action
$errorCode = $th->getCode();
} finally {
/** Update execution status */
try {
$execution = $dbForProject->updateDocument('executions', $executionId, $execution);
} catch (\Throwable $e) {
$log->addExtra('updateError', $e->getMessage());
if (System::getEnv('_APP_REGION') !== 'nyc') { // TODO: Remove region check
try {
$execution = $dbForProject->updateDocument('executions', $executionId, $execution);
} catch (\Throwable $e) {
$log->addExtra('updateError', $e->getMessage());
}
}
/** Trigger usage queue */