MCPcopy
hub / github.com/codeaashu/claude-code / readCronTasks

Function readCronTasks

src/utils/cronTasks.ts:91–140  ·  view source on GitHub ↗
(dir?: string)

Source from the content-addressed store, hash-verified

89 * blocks the whole file.
90 */
91export async function readCronTasks(dir?: string): Promise<CronTask[]> {
92 const fs = getFsImplementation()
93 let raw: string
94 try {
95 raw = await fs.readFile(getCronFilePath(dir), { encoding: 'utf-8' })
96 } catch (e: unknown) {
97 if (isFsInaccessible(e)) return []
98 logError(e)
99 return []
100 }
101
102 const parsed = safeParseJSON(raw, false)
103 if (!parsed || typeof parsed !== 'object') return []
104 const file = parsed as Partial<CronFile>
105 if (!Array.isArray(file.tasks)) return []
106
107 const out: CronTask[] = []
108 for (const t of file.tasks) {
109 if (
110 !t ||
111 typeof t.id !== 'string' ||
112 typeof t.cron !== 'string' ||
113 typeof t.prompt !== 'string' ||
114 typeof t.createdAt !== 'number'
115 ) {
116 logForDebugging(
117 `[ScheduledTasks] skipping malformed task: ${jsonStringify(t)}`,
118 )
119 continue
120 }
121 if (!parseCronExpression(t.cron)) {
122 logForDebugging(
123 `[ScheduledTasks] skipping task ${t.id} with invalid cron '${t.cron}'`,
124 )
125 continue
126 }
127 out.push({
128 id: t.id,
129 cron: t.cron,
130 prompt: t.prompt,
131 createdAt: t.createdAt,
132 ...(typeof t.lastFiredAt === 'number'
133 ? { lastFiredAt: t.lastFiredAt }
134 : {}),
135 ...(t.recurring ? { recurring: true } : {}),
136 ...(t.permanent ? { permanent: true } : {}),
137 })
138 }
139 return out
140}
141
142/**
143 * Sync check for whether the cron file has any valid tasks. Used by

Callers 5

addCronTaskFunction · 0.85
removeCronTasksFunction · 0.85
markCronTasksFiredFunction · 0.85
listAllCronTasksFunction · 0.85
loadFunction · 0.85

Calls 9

getFsImplementationFunction · 0.85
getCronFilePathFunction · 0.85
isFsInaccessibleFunction · 0.85
logForDebuggingFunction · 0.85
jsonStringifyFunction · 0.85
parseCronExpressionFunction · 0.85
readFileMethod · 0.80
logErrorFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected