|
7 | 7 | from astrbot.core.agent.run_context import ContextWrapper |
8 | 8 | from astrbot.core.agent.tool import FunctionTool, ToolExecResult |
9 | 9 | from astrbot.core.astr_agent_context import AstrAgentContext |
| 10 | +from astrbot.core.cron.manager import CronJobSchedulingError |
10 | 11 | from astrbot.core.tools.registry import builtin_tool |
11 | 12 |
|
12 | 13 | _CRON_TOOL_CONFIG = { |
@@ -112,14 +113,17 @@ async def call( |
112 | 113 | "origin": "tool", |
113 | 114 | } |
114 | 115 |
|
115 | | - job = await cron_mgr.add_active_job( |
116 | | - name=name, |
117 | | - cron_expression=str(cron_expression) if cron_expression else None, |
118 | | - payload=payload, |
119 | | - description=note, |
120 | | - run_once=run_once, |
121 | | - run_at=run_at_dt, |
122 | | - ) |
| 116 | + try: |
| 117 | + job = await cron_mgr.add_active_job( |
| 118 | + name=name, |
| 119 | + cron_expression=str(cron_expression) if cron_expression else None, |
| 120 | + payload=payload, |
| 121 | + description=note, |
| 122 | + run_once=run_once, |
| 123 | + run_at=run_at_dt, |
| 124 | + ) |
| 125 | + except CronJobSchedulingError: |
| 126 | + return "error: failed to schedule task due to invalid configuration." |
123 | 127 | next_run = job.next_run_time or run_at_dt |
124 | 128 | suffix = ( |
125 | 129 | f"one-time at {next_run}" |
@@ -195,7 +199,10 @@ async def call( |
195 | 199 | updates["cron_expression"] = cron_expression |
196 | 200 | updates["payload"] = payload |
197 | 201 |
|
198 | | - job = await cron_mgr.update_job(str(job_id), **updates) |
| 202 | + try: |
| 203 | + job = await cron_mgr.update_job(str(job_id), **updates) |
| 204 | + except CronJobSchedulingError: |
| 205 | + return "error: failed to update task due to invalid configuration." |
199 | 206 | if not job: |
200 | 207 | return f"error: cron job {job_id} not found." |
201 | 208 | return f"Updated future task {job.job_id} ({job.name})." |
|
0 commit comments