MCPcopy Create free account
hub / github.com/Noumena-Network/code / startBackgroundHousekeeping

Function startBackgroundHousekeeping

src/utils/backgroundHousekeeping.ts:36–103  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

34const DELAY_VERY_SLOW_OPERATIONS_THAT_HAPPEN_EVERY_SESSION = 10 * 60 * 1000
35
36export function startBackgroundHousekeeping(): void {
37 if (isDeferredHeadlessPluginStartupSurfacesEnabled()) {
38 return
39 }
40
41 void initMagicDocs()
42 void initSkillImprovement()
43 if (feature('EXTRACT_MEMORIES')) {
44 extractMemoriesModule!.initExtractMemories()
45 }
46 initAutoDream()
47 void autoUpdateMarketplacesAndPluginsInBackground()
48 if (feature('LODESTONE') && getIsInteractive()) {
49 void registerProtocolModule!.ensureDeepLinkProtocolRegistered()
50 }
51
52 let needsCleanup = true
53 async function runVerySlowOps(): Promise<void> {
54 // If the user did something in the last minute, don't make them wait for these slow operations to run.
55 if (
56 getIsInteractive() &&
57 getLastInteractionTime() > Date.now() - 1000 * 60
58 ) {
59 setTimeout(
60 runVerySlowOps,
61 DELAY_VERY_SLOW_OPERATIONS_THAT_HAPPEN_EVERY_SESSION,
62 ).unref()
63 return
64 }
65
66 if (needsCleanup) {
67 needsCleanup = false
68 await cleanupOldMessageFilesInBackground()
69 }
70
71 // If the user did something in the last minute, don't make them wait for these slow operations to run.
72 if (
73 getIsInteractive() &&
74 getLastInteractionTime() > Date.now() - 1000 * 60
75 ) {
76 setTimeout(
77 runVerySlowOps,
78 DELAY_VERY_SLOW_OPERATIONS_THAT_HAPPEN_EVERY_SESSION,
79 ).unref()
80 return
81 }
82
83 await cleanupOldVersions()
84 }
85
86 setTimeout(
87 runVerySlowOps,
88 DELAY_VERY_SLOW_OPERATIONS_THAT_HAPPEN_EVERY_SESSION,
89 ).unref()
90
91 // For long-running sessions, schedule recurring cleanup every 24 hours.
92 // Both cleanup functions use marker files and locks to throttle to once per day
93 // and skip immediately if another process holds the lock.

Callers 1

REPLFunction · 0.85

Tested by

no test coverage detected