gitoria

jukebox

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Branchday39cfe95440|||PR day39 re-vendor: Hybriel 51e921d7 (bin 6b481aa7), ids kebab-case since hybriel#256: quoted state rule and tests use jb-shuffle / jb-repeatmreday39/lib/schedule.hl

2.8 KB

  1. // lib/schedule.hl — WHEN A SCAN RUNS, and how: once shortly after the start, then every `rescanMinutes` (settings, default
  2. // 30) after the last one finished, and whenever someone asks (POST /api/rescan sets `wanted`). project.hl calls `tick`
  3. // once a second. Only one scan runs at a time. JUKEBOX_AUTOSCAN=0 turns the timed scans off (tests); asking still works.
  4. // THE SCAN RUNS IN A CHILD PROCESS (tools/scan.hl, under nice and ionice): a scan inside the server would hold it up for
  5. // minutes (measured: 2,391 files, the server answered nothing until the scan was over). The child prints its progress as
  6. // lines; the server shows them in /api/stats, and drops its order lists when the child has exited.
  7. import { now } from 'hl:time'
  8. import { spawnArgs, dir } from 'hl:proc'
  9. import { loadSettings } from './settings.hl'
  10. import { scanState } from './library.hl'
  11. import { dropOrderCache } from './state.hl'
  12. import { envOr, storageRoot } from './util.hl'
  13. static autoscan = envOr('JUKEBOX_AUTOSCAN', '1') != '0'
  14. static armFirst = () => {
  15. scanState.nextAt = autoscan ? now() + 2000 : 0
  16. }
  17. // ask for a scan; answers false when one is already running
  18. static requestScan = () => {
  19. if (scanState.running) { return false }
  20. scanState.wanted = true
  21. return true
  22. }
  23. // a progress line of the child → the state
  24. static applyLine = (line) => {
  25. if (!line.startsWith('JB-PROGRESS ')) { return false }
  26. p = JSON.parse(line.slice(12))
  27. st = scanState
  28. st.phase = p.phase
  29. st.seen = p.seen
  30. st.added = p.added
  31. st.updated = p.updated
  32. st.removed = p.removed
  33. st.unreadable = p.unreadable
  34. return true
  35. }
  36. // start the child; answers the Process (project.hl listens to its events) or null when nothing was due
  37. static tick = () => {
  38. st = scanState
  39. if (st.running) { return null }
  40. due = st.wanted || (st.nextAt > 0 && now() >= st.nextAt)
  41. if (!due) { return null }
  42. st.wanted = false
  43. st.running = true
  44. st.phase = 'starting'
  45. st.seen = 0
  46. st.added = 0
  47. st.updated = 0
  48. st.removed = 0
  49. st.unreadable = 0
  50. st.startedAt = now()
  51. st.lastError = ''
  52. app = dir()
  53. child = spawnArgs(['nice', '-n', '19', 'ionice', '-c3', app + '/bin/hybriel', app + '/tools/scan.hl'], { env = { JUKEBOX_PROGRESS = '1' JUKEBOX_STORAGE = storageAbs() } })
  54. return child
  55. }
  56. // the child's storage path must be absolute (its script directory differs)
  57. static storageAbs = () => {
  58. if (storageRoot.startsWith('/')) { return storageRoot }
  59. return dir() + '/' + (storageRoot.startsWith('./') ? storageRoot.slice(2) : storageRoot)
  60. }
  61. // the child ended
  62. static finished = (exitCode) => {
  63. st = scanState
  64. st.running = false
  65. st.finishedAt = now()
  66. st.lastSeconds = (st.finishedAt - st.startedAt) / 1000
  67. if (exitCode != 0) { st.lastError = 'the scan process ended with status ' + exitCode }
  68. st.phase = 'idle'
  69. dropOrderCache()
  70. s = loadSettings()
  71. st.nextAt = autoscan ? now() + s.rescanMinutes * 60000 : 0
  72. }

Branches

Latest commits

  • cfe95440|||PR day39 re-vendor: Hybriel 51e921d7 (bin 6b481aa7), ids kebab-case since hybriel#256: quoted state rule and tests use jb-shuffle / jb-repeatmre
  • f3614c9bRe-vendor to Hybriel day39 (51e921d7, bin 6b481aa7)mre
  • 9f5c6532Merge branch 'status-22-pr' into mainJukebox
  • 5838d6c7|||PR STATUS: #22 pending decision, PR-only rulemre
  • 29d2029cRecords: PR-only rule (Kunibert)mre
  • adacb0abRecords: neutral ticket rule, #22 decision recordedmre
  • b2d6f121Records: #308 hold liftedmre
  • 7ab67533Records: day39 on hold (hybriel#308)mre
  • 22f21739Records: note rebase before mergemre
  • f7368ea3Records: mission 011 day39, waits for lisbethmre
  • 9515d2cdRecords: jb20 livemre
  • 019f6601ui gate: comment names the open bug components#27 (workaround, not fixed)mre
  • 277a2722README: provenance linemre
  • 4169ca6aREADME: sync pinmre
  • a01f3aa8ui gate: back to the top before the sort checks (the screen reopens where it was left)mre
  • f7936c20Lists keep their scroll position across a reload (jukebox#20): per-list offsets in storage/ui.json, gate jb20mre
  • d67906devirtual-list and icons from components.hybriel e5b98ec (centerId, scrollTop, onScroll)mre
  • df7920ceRecords: R3 startedmre
  • 0549f038Mission 010: jb20 livemre
  • 273494e2STATUS rewrittenmre