Skip to content

feat: make course reindexing on init optional, and schedulable on k8s - #1558

Draft
ahmed-arb wants to merge 2 commits into
releasefrom
ahmed-arb/skip-reindex-course
Draft

ahmed-arb wants to merge 2 commits into
releasefrom
ahmed-arb/skip-reindex-course

Conversation

@ahmed-arb

Copy link
Copy Markdown
Collaborator

Description

Closes #1549.

We reindex courses on every init. Upstream this is still a synchronous loop over every active course, so on instances with hundreds of courses it adds a long, blocking step to every deploy. In practice, operators of large instances end up removing it and reindexing from external cron jobs instead.

This PR adds two settings:

  • OPENEDX_INIT_REINDEX_COURSES (default: true): set it to false to skip the reindex during CMS init. The default keeps the current behaviour.
  • OPENEDX_REINDEX_COURSES_SCHEDULE (default: ""): a cron expression. When set, tutor k8s start creates a cms-reindex-courses CronJob that runs reindex_course --active on that schedule. It reuses the cms-job pod spec and sets concurrencyPolicy: Forbid.

Used together, they move course reindexing out of the deploy path and into a schedule.

I first tried skipping the reindex automatically whenever the Meilisearch course index already had documents, but testing showed that's unsafe. On-publish indexing (update_search_index) is incremental: it only indexes blocks edited within REINDEX_AGE (60s). So courses that are imported, or whose index is lost, never get their courseware indexed except through reindex_course. That's why skipping stays an explicit opt-out, documented with this caveat.

Docker Compose has no scheduler, so the CronJob is k8s-only. For `test a host crontab entry instead.

Testing

  • Ran a full tutor local do init on a fresh install: the reindex runs as before.
  • With the demo course imported, ran tutor local do init --limit cNDEX_COURSES set to true (reindex runs) and to false (the stepis skipped and the skip message is printed).
  • Ran kubectl kustomize on the rendered env with the schedule unscms-reindex-courses` with the expected schedule, command, labels and namespace).
  • On a kind cluster: tutor k8s start created the CronJob, a job tate job --from=cronjob/cms-reindex-coursescompleted successfully,andtutor k8s stop` deleted it. (pending)
  • Unit tests pass (python -m unittest discover tests).

🤖 Generated with Claude Code

`do init` runs `reindex_course --active`, a synchronous loop over every
active course, which makes every launch slow on large instances (#1197).

Add `OPENEDX_INIT_REINDEX_COURSES` (default: true) to skip it, and
`OPENEDX_REINDEX_COURSES_SCHEDULE` (default: "") to run it from a k8s
CronJob instead. Skipping is opt-in rather than automatic: on-publish
indexing only covers blocks edited within REINDEX_AGE, so imported
courses only reach the courseware index through `reindex_course`.

Also add the `k8s-cronjobs` patch and delete CronJobs on `tutor k8s stop`.

Close #1549.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ahmed-arb
ahmed-arb marked this pull request as draft November 13, 2026 12:27
@ahmed-arb ahmed-arb self-assigned this Nov 13, 2026
- Don't let jobs spawned by a CronJob block `tutor k8s do` commands:
  they inherit Tutor's labels, so `active_job_names()` treated a long
  scheduled reindex as an active job and `do init`/`launch` waited on it.
- Only list k8s/cronjobs.yml in the kustomization when it has content.
- Render the schedule with `tojson` so that quotes can't break the YAML.
- Docs: mention the control plane timezone, that cms-job overrides don't
  apply to the CronJob, and use `tutor local run` in the crontab example
  (it passes -T without a TTY and doesn't need cms to be running). Fix the
  k8s-cronjobs patch description.
- Keep defaults.yml in alphabetical order.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Pending Triage

Development

Successfully merging this pull request may close these issues.

reindex_course --active still blocks cms init on every launch

1 participant