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

Function addCronTask

src/utils/cronTasks.ts:212–237  ·  view source on GitHub ↗
(
  cron: string,
  prompt: string,
  recurring: boolean,
  durable: boolean,
  agentId?: string,
)

Source from the content-addressed store, hash-verified

210 * change event is needed.
211 */
212export async function addCronTask(
213 cron: string,
214 prompt: string,
215 recurring: boolean,
216 durable: boolean,
217 agentId?: string,
218): Promise<string> {
219 // Short ID — 8 hex chars is plenty for MAX_JOBS=50, avoids slice/prefix
220 // juggling between the tool layer (shows short IDs) and disk.
221 const id = randomUUID().slice(0, 8)
222 const task = {
223 id,
224 cron,
225 prompt,
226 createdAt: Date.now(),
227 ...(recurring ? { recurring: true } : {}),
228 }
229 if (!durable) {
230 addSessionCronTask({ ...task, ...(agentId ? { agentId } : {}) })
231 return id
232 }
233 const tasks = await readCronTasks()
234 tasks.push(task)
235 await writeCronTasks(tasks)
236 return id
237}
238
239/**
240 * Remove tasks by id. No-op if none match (e.g. another session raced us).

Callers 1

callFunction · 0.85

Calls 4

randomUUIDFunction · 0.90
addSessionCronTaskFunction · 0.85
readCronTasksFunction · 0.85
writeCronTasksFunction · 0.85

Tested by

no test coverage detected