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:
@@ -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)) {
|
||||
|
||||
Reference in New Issue
Block a user