{"record":{"id":"c91b0cec47b13eb2","repo":"Budibase/budibase","slug":"failed-to-enable-cron-or-email-trigger-for-automat","errorCode":null,"errorMessage":"Failed to enable CRON or Email trigger for automation \"${automation.name}\": ${err.message}","messagePattern":"Failed to enable CRON or Email trigger for automation \"(.+?)\": (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/server/src/api/controllers/deploy/index.ts","lineNumber":119,"sourceCode":"    await db.allDocs<Automation>(\n      getAutomationParams(null, {\n        include_docs: true,\n      })\n    )\n  ).rows.map(row => row.doc!)\n  await clearMetadata()\n  let { count } = await disableAllCrons(prodAppId)\n  const promises = []\n\n  for (let automation of automations) {\n    promises.push(\n      enableCronOrEmailTrigger(prodAppId, automation)\n        .then(({ enabled, automation, clearedRepeatableJobs }) => {\n          count += clearedRepeatableJobs\n          return { enabled, automation }\n        })\n        .catch(err => {\n          throw new Error(\n            `Failed to enable CRON or Email trigger for automation \"${automation.name}\": ${err.message}`,\n            { cause: err }\n          )\n        })\n    )\n  }\n  const results = await Promise.all(promises)\n  const enabledCount = results\n    .map(result => result.enabled)\n    .filter(result => result).length\n  console.log(\n    `Cleared ${count} old CRON/email, enabled ${enabledCount} new CRON/email triggers for app deployment`\n  )\n\n  const knowledgeSourceSyncSummary = await context.doInWorkspaceContext(\n    prodAppId,\n    async () => {\n      const agents = await sdk.ai.agents.fetch()","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/api/controllers/deploy/index.ts#L101-L137","documentation":"During publish, initDeployedApp re-enables CRON and email triggers for each production automation. If enabling any trigger rejects, the rejection is re-thrown as a new Error wrapping the cause with this message naming the automation. It aggregates quartz/queue-level failures into the deployment flow.","triggerScenarios":"enableCronOrEmailTrigger fails for a specific automation during publishWorkspaceInternal — e.g. Quartz job registration throws, a Redis/BullMQ queue error occurs, the automation has a malformed CRON expression, or an email trigger config is invalid.","commonSituations":"Corrupted automation doc after import; CRON string that the scheduler rejects; Redis unavailable or flushed mid-publish; duplicate repeatable jobs from a previous failed publish.","solutions":["Read the cause (err.cause) to find the underlying Quartz/Redis failure","Open the named automation in the builder and validate/fix its CRON expression or email trigger config","Check Redis connectivity and health for the worker during publish","Delete and re-save the offending automation trigger to rebuild its schedule","Re-run the publish after fixing the automation"],"exampleFix":"// before\ncron: \"0 25 6 * * *\"\n// after ( Quartz requires 6-7 fields; verify format )\ncron: \"0 0 6 * * ?\"","handlingStrategy":"try-catch","validationCode":"const cron = automation.definition?.trigger?.inputs?.cron\nif (cron && !/^\\S+\\s+\\S+\\s+\\S+\\s+\\S+\\s+\\S+(\\s+\\S+)?$/.test(cron.trim())) {\n  throw new Error(`Automation ${automation.name} has invalid cron: ${cron}`)\n}\n","typeGuard":null,"tryCatchPattern":"try {\n  await api.post(`/api/applications/${appId}/publish`)\n} catch (err) {\n  if (err.message.startsWith(\"Failed to enable CRON or Email trigger\")) {\n    console.error(\"Automation:\", err.message, \"cause:\", err.cause)\n    // fix the named automation's trigger, then re-publish\n  } else { throw err }\n}\n","preventionTips":["Validate CRON expressions in the builder before saving automations","Keep Redis healthy and monitored during publishes","Avoid importing automations with corrupt trigger definitions","Re-save automation triggers after bulk imports"],"tags":["automation","cron","publish","scheduler"],"backgroundTag":"cron-trigger-setup-failed","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}