jukebox
All repositories: gitoria
2.8 KB
// lib/schedule.hl — WHEN A SCAN RUNS, and how: once shortly after the start, then every `rescanMinutes` (settings, default// 30) after the last one finished, and whenever someone asks (POST /api/rescan sets `wanted`). project.hl calls `tick`// once a second. Only one scan runs at a time. JUKEBOX_AUTOSCAN=0 turns the timed scans off (tests); asking still works.// THE SCAN RUNS IN A CHILD PROCESS (tools/scan.hl, under nice and ionice): a scan inside the server would hold it up for// minutes (measured: 2,391 files, the server answered nothing until the scan was over). The child prints its progress as// lines; the server shows them in /api/stats, and drops its order lists when the child has exited.import { now } from 'hl:time'import { spawnArgs, dir } from 'hl:proc'import { loadSettings } from './settings.hl'import { scanState } from './library.hl'import { dropOrderCache } from './state.hl'import { envOr, storageRoot } from './util.hl'static autoscan = envOr('JUKEBOX_AUTOSCAN', '1') != '0'static armFirst = () => {scanState.nextAt = autoscan ? now() + 2000 : 0}// ask for a scan; answers false when one is already runningstatic requestScan = () => {if (scanState.running) { return false }scanState.wanted = truereturn true}// a progress line of the child → the statestatic applyLine = (line) => {if (!line.startsWith('JB-PROGRESS ')) { return false }p = JSON.parse(line.slice(12))st = scanStatest.phase = p.phasest.seen = p.seenst.added = p.addedst.updated = p.updatedst.removed = p.removedst.unreadable = p.unreadablereturn true}// start the child; answers the Process (project.hl listens to its events) or null when nothing was duestatic tick = () => {st = scanStateif (st.running) { return null }due = st.wanted || (st.nextAt > 0 && now() >= st.nextAt)if (!due) { return null }st.wanted = falsest.running = truest.phase = 'starting'st.seen = 0st.added = 0st.updated = 0st.removed = 0st.unreadable = 0st.startedAt = now()st.lastError = ''app = dir()child = spawnArgs(['nice', '-n', '19', 'ionice', '-c3', app + '/bin/hybriel', app + '/tools/scan.hl'], { env = { JUKEBOX_PROGRESS = '1' JUKEBOX_STORAGE = storageAbs() } })return child}// the child's storage path must be absolute (its script directory differs)static storageAbs = () => {if (storageRoot.startsWith('/')) { return storageRoot }return dir() + '/' + (storageRoot.startsWith('./') ? storageRoot.slice(2) : storageRoot)}// the child endedstatic finished = (exitCode) => {st = scanStatest.running = falsest.finishedAt = now()st.lastSeconds = (st.finishedAt - st.startedAt) / 1000if (exitCode != 0) { st.lastError = 'the scan process ended with status ' + exitCode }st.phase = 'idle'dropOrderCache()s = loadSettings()st.nextAt = autoscan ? now() + s.rescanMinutes * 60000 : 0}
Branches
Latest commits
- fa86b08c|||PR Records 2026-11-24: LOG, STATUS, missions 020-023mre
- 0a2ae3daMerge remote-tracking branch 'origin/records-1123' into records-1124mre
- 9a48cfcaMerge branch 'vendor-theme' into mainJukebox
- 170d3735Merge branch 'code-order-2' into mainJukebox
- 3f1918a7|||PR Re-sync layouts theme 4099e64 with Segoe UI firstmre
- 2e7f6a43Vendor virtual-list 489afcf from components.hybrielmre
- 0ba85799Merge branch 'reset-classes' into mainJukebox
- 502eeed5jukebox#20: vendor virtual-list initial resetKey baseline fixmre
- 6d5ce287|||PR jukebox#9 Centralize songs table reads and writes in db.hlmre
- dcca21abjukebox#8 Move copies and queue logic into their topicsmre
- 3b76651cjukebox#20: update virtual-list README pin and resetKey optionsmre
- bc09e1e8|||PR jukebox#20: reset virtual lists through resetKey (partial validation)mre
- a3796dc5Records: live step waits for idlemre
- 3b158e16Records: merges of #9 and #11mre
- 27204167Merge main into records-1123mre
- 10f8a8c8Merge branch 'code-order' into mainJukebox
- 204fc828Merge branch 'day72' into mainJukebox
- 8e8d0e2b|||PR Records: PROCEDURES.md, missions 016-019, GO 2026-11-23mre
- 95f5faae|||PR jukebox#7 Drop needless let declarationsmre
- 33072bb5|||PR Record day72 gates and Chrome proofmre