HKUDS/DeepTutor · error · ValueError

'every' interval must be at least 30 seconds

Error message

'every' interval must be at least 30 seconds

What it means

validate_schedule enforces a 30-second minimum for 'every' (interval) schedules: every_seconds must be truthy and >= 30. The floor prevents tight-loop jobs from hammering the single-process scheduler and downstream LLM endpoints.

Source

Thrown at deeptutor/services/cron/service.py:161

                "use an 'every' or 'at' schedule instead"
            ) from None
        except Exception as exc:
            raise ValueError(f"invalid cron expression {schedule.expr!r}: {exc}") from None

    return None


def validate_schedule(schedule: CronSchedule) -> None:
    """Reject schedules that could never run (raises ValueError)."""
    if schedule.kind == "at":
        if not schedule.at_ms:
            raise ValueError("'at' schedules need a time")
        if schedule.at_ms <= _now_ms():
            raise ValueError("'at' time is in the past")
        return
    if schedule.kind == "every":
        if not schedule.every_seconds or schedule.every_seconds < 30:
            raise ValueError("'every' interval must be at least 30 seconds")
        return
    if schedule.kind == "cron":
        if schedule.tz:
            try:
                from zoneinfo import ZoneInfo

                ZoneInfo(schedule.tz)
            except Exception:
                raise ValueError(f"unknown timezone {schedule.tz!r}") from None
        # Raises ValueError on bad/unsupported expressions.
        if compute_next_run(schedule, _now_ms()) is None:
            raise ValueError(f"cron expression {schedule.expr!r} never fires")
        return
    raise ValueError(f"unknown schedule kind {schedule.kind!r}")


class CronService:
    """Single-process job store + scheduler."""

View on GitHub (pinned to 3e82f13042)

Solutions

  1. Raise the interval to at least 30 seconds
  2. For tests, mock the scheduler clock rather than shipping a sub-30 production config
  3. Double-check units — 30 means 30 seconds, not 30 minutes

Example fix

# before
sched = CronSchedule(kind="every", every_seconds=5)  # ValueError
# after
sched = CronSchedule(kind="every", every_seconds=30)  # minimum allowed
Defensive patterns

Strategy: validation

Validate before calling

MIN_EVERY_SECONDS = 30
def valid_every(s: CronSchedule) -> bool:
    return s.kind != "every" or (bool(s.every_seconds) and s.every_seconds >= MIN_EVERY_SECONDS)

Try / catch

try:
    svc.add_job(schedule, ...)
except ValueError as e:
    if "at least 30 seconds" in str(e):
        schedule.every_seconds = 30
        svc.add_job(schedule, ...)
    else:
        raise

Prevention

When it happens

Trigger: CronSchedule(kind="every", every_seconds=10) or every_seconds=None/0 passed to add_job/validate_schedule.

Common situations: Prototyping with a 5s interval to observe firing; tests wanting fast ticks; UI allowing sub-30 values; unit confusion (minutes vs seconds).

Related errors


AI-assisted analysis of HKUDS/DeepTutor@3e82f13042 (2026-08-27). Data as JSON: /api/errors/fe0abddf297e0122. Report an issue: GitHub.