Skip to content

Remove completed one-time jobs from Scheduler._jobs_by_name #450

@jessica-claude

Description

@jessica-claude

Description

One-time named jobs that complete naturally are removed from the SchedulerService heap but not from Scheduler._jobs_by_name. Re-scheduling with the same name raises ValueError, and if_exists="skip" returns a stale (completed, unqueued) job object.

Steps to Reproduce

  1. Schedule a named one-time job: scheduler.run_once(func, delay=5, name="cleanup")
  2. Wait for it to complete
  3. Schedule again with the same name: scheduler.run_once(func, delay=5, name="cleanup")
  4. Gets ValueError: A job named 'cleanup' already exists

Expected Behavior

Completed one-time jobs should be removed from _jobs_by_name so the name can be reused.

Acceptance Criteria

  • Completed one-time jobs are removed from Scheduler._jobs_by_name after execution
  • Re-scheduling with the same name after completion works
  • if_exists="skip" does not return stale completed job objects
  • Existing tests pass; new test for name reuse after completion

Context

Found during post-execution challenge review of bus/scheduler hardening (#437, #412, #414, #436). Pre-existing issue, not introduced by the hardening changes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:schedulerScheduler servicebugSomething isn't workingsize:smallQuick win, < 1 hour

    Projects

    Status

    Refinement

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions