mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-04-02 09:22:36 +00:00
feat(cron): add deliver parameter to support silent jobs, default true for backward compatibility
This commit is contained in:
parent
a3e4c77fff
commit
73e80b199a
@ -97,9 +97,14 @@ class CronTool(Tool):
|
||||
f"(e.g. '2026-02-12T10:30:00'). Naive values default to {self._default_timezone}."
|
||||
),
|
||||
},
|
||||
"job_id": {"type": "string", "description": "Job ID (for remove)"},
|
||||
},
|
||||
"required": ["action"],
|
||||
"job_id": {"type": "string", "description": "Job ID (for remove)"},
|
||||
"deliver": {
|
||||
"type": "boolean",
|
||||
"description": "Whether to deliver the execution result to the user channel (default true)",
|
||||
"default": true
|
||||
},
|
||||
},
|
||||
"required": ["action"],
|
||||
}
|
||||
|
||||
async def execute(
|
||||
@ -111,12 +116,13 @@ class CronTool(Tool):
|
||||
tz: str | None = None,
|
||||
at: str | None = None,
|
||||
job_id: str | None = None,
|
||||
deliver: bool = True,
|
||||
**kwargs: Any,
|
||||
) -> str:
|
||||
if action == "add":
|
||||
if self._in_cron_context.get():
|
||||
return "Error: cannot schedule new jobs from within a cron job execution"
|
||||
return self._add_job(message, every_seconds, cron_expr, tz, at)
|
||||
return self._add_job(message, every_seconds, cron_expr, tz, at, deliver)
|
||||
elif action == "list":
|
||||
return self._list_jobs()
|
||||
elif action == "remove":
|
||||
@ -130,6 +136,7 @@ class CronTool(Tool):
|
||||
cron_expr: str | None,
|
||||
tz: str | None,
|
||||
at: str | None,
|
||||
deliver: bool = True,
|
||||
) -> str:
|
||||
if not message:
|
||||
return "Error: message is required for add"
|
||||
@ -171,7 +178,7 @@ class CronTool(Tool):
|
||||
name=message[:30],
|
||||
schedule=schedule,
|
||||
message=message,
|
||||
deliver=True,
|
||||
deliver=deliver,
|
||||
channel=self._channel,
|
||||
to=self._chat_id,
|
||||
delete_after_run=delete_after,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user