mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
Activate the function schedule on jobs build success
The executor Builds worker (re)activates a function's schedule document on build completion (`schedules.active = has-cron && has-deployment`) so the scheduler enqueues cron executions. The jobs worker only updated the function + rules, so jobs-built scheduled functions were never enqueued — FunctionsSchedule E2E saw 0 executions. Mirror the executor: after activation, update the schedule doc's active/schedule/resourceUpdatedAt. Verified locally: testCreateScheduledExecution passes (cron execution fires). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
a894a8f2b1
commit
362ed333b8
1 file changed
+31
-1
@@ -274,9 +274,12 @@ class Jobs extends Action
|
||||
BuildUsage::publish($usage, $function, $deployment, $project, $publisherForUsage);
|
||||
}
|
||||
|
||||
// Keep the function's "latest deployment" pointer + status current.
|
||||
// Keep the function's "latest deployment" pointer + status current, and
|
||||
// (re)activate its schedule so the scheduler enqueues cron executions —
|
||||
// both mirror the executor Builds worker on build completion.
|
||||
if (! $function->isEmpty()) {
|
||||
$this->updateLatestDeployment($dbForProject, $function);
|
||||
$this->schedule($dbForProject, $dbForPlatform, $function);
|
||||
}
|
||||
|
||||
// Report the terminal outcome as a VCS commit status (jobs-built VCS
|
||||
@@ -382,6 +385,33 @@ class Jobs extends Action
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* (Re)activate the function's schedule document so the scheduler enqueues
|
||||
* cron executions. Mirrors the executor Builds worker: a schedule is active
|
||||
* only when the function has both a cron expression and an active
|
||||
* deployment. Re-reads the function so it sees a deploymentId just set by
|
||||
* activate().
|
||||
*/
|
||||
private function schedule(Database $dbForProject, Database $dbForPlatform, Document $function): void
|
||||
{
|
||||
$scheduleId = $function->getAttribute('scheduleId', '');
|
||||
if ($scheduleId === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
$function = $dbForProject->getDocument('functions', $function->getId());
|
||||
$schedule = $dbForPlatform->getDocument('schedules', $scheduleId);
|
||||
if ($schedule->isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$dbForPlatform->updateDocument('schedules', $schedule->getId(), new Document([
|
||||
'resourceUpdatedAt' => DateTime::now(),
|
||||
'schedule' => $function->getAttribute('schedule', ''),
|
||||
'active' => ! empty($function->getAttribute('schedule')) && ! empty($function->getAttribute('deploymentId')),
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify project webhooks and event-triggered functions of a deployment
|
||||
* update, mirroring the executor Builds worker's fan-out. queueForEvents
|
||||
|
||||
Reference in new issue
Block a user