feat(scheduler): delete orphaned jobs and block editing of unregistered jobs

Adds deleteOrphanedJobs() to clean up stale job_keys during ensureSystemJobs, and prevents editing jobs that are no longer registered in the runtime registry.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-13 14:13:09 +02:00
parent 1c784efd5c
commit 312d43d9d9
7 changed files with 69 additions and 0 deletions

View File

@@ -240,6 +240,22 @@ class ScheduledJobRepository implements ScheduledJobRepositoryInterface
return $updated !== false;
}
public function deleteOrphanedJobs(array $validKeys): int
{
$validKeys = array_filter(array_map('trim', $validKeys), static fn (string $k): bool => $k !== '');
if ($validKeys === []) {
return 0;
}
$placeholders = implode(',', array_fill(0, count($validKeys), '?'));
$affected = DB::update(
"DELETE FROM scheduled_jobs WHERE job_key NOT IN ({$placeholders})",
...array_map('strval', $validKeys)
);
return (int) $affected;
}
private function normalizeRow(mixed $row): ?array
{
if (!is_array($row)) {

View File

@@ -28,4 +28,7 @@ interface ScheduledJobRepositoryInterface
?string $errorCode,
?string $errorMessage
): bool;
/** Delete jobs whose job_key is not in the given list of valid keys. Returns affected row count. */
public function deleteOrphanedJobs(array $validKeys): int;
}