MCPcopy Index your code
hub / github.com/ChatLab/ChatLab / startTimer

Function startTimer

packages/sync/src/scheduler.ts:26–53  ·  view source on GitHub ↗
(ds: DataSource, skipInitialPull = false)

Source from the content-addressed store, hash-verified

24let _logger: SyncLogger
25
26function startTimer(ds: DataSource, skipInitialPull = false): void {
27 stopTimer(ds.id)
28 if (!ds.enabled || ds.intervalMinutes < 1 || ds.sessions.length === 0) return
29
30 const intervalMs = ds.intervalMinutes * 60 * 1000
31
32 if (!skipInitialPull) {
33 _pullEngine.pullAllSessions(ds).catch((err) => {
34 _logger.error('[Pull] Initial pull failed', err)
35 })
36 }
37
38 const timer = setInterval(() => {
39 const current = _dsManager.loadAll().find((s) => s.id === ds.id)
40 if (!current || !current.enabled || current.sessions.length === 0) {
41 stopTimer(ds.id)
42 return
43 }
44 _pullEngine.pullAllSessions(current).catch((err) => {
45 _logger.error('[Pull] Scheduled pull failed', err)
46 })
47 }, intervalMs)
48
49 timers.set(ds.id, timer)
50 _logger.info(
51 `[Pull] Timer started for source ${ds.baseUrl} (${ds.sessions.length} sessions, every ${ds.intervalMinutes}min)`
52 )
53}
54
55export function stopTimer(id: string): void {
56 const timer = timers.get(id)

Callers 2

initSchedulerFunction · 0.85
reloadTimerFunction · 0.85

Calls 6

stopTimerFunction · 0.85
pullAllSessionsMethod · 0.80
setMethod · 0.80
errorMethod · 0.65
infoMethod · 0.65
loadAllMethod · 0.45

Tested by

no test coverage detected