Skip to content

JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.

Python

fix: 修改定时任务不能及时返回的问题

Haowei_Du3676167fcb30
diff --git a/jiuwenclaw/channel/web_channel.py b/jiuwenclaw/channel/web_channel.py
index f224b91c03..2ec267e7eb 100644
--- a/jiuwenclaw/channel/web_channel.py
+++ b/jiuwenclaw/channel/web_channel.py
@@ -320,7 +320,7 @@ class WebChannel(BaseChannel):
async for raw in ws:
await self._handle_raw_message(ws, raw, query)
except Exception as e: # pragma: no cover - 连接生命周期容错
- logger.warning("WebChannel 连接异常: {}", e)
+ logger.warning("WebChannel 连接异常: %s", e)
finally:
self._clients.discard(ws)
logger.info(f"WebChannel 连接关闭: remote={remote}")
diff --git a/jiuwenclaw/gateway/cron/scheduler.py b/jiuwenclaw/gateway/cron/scheduler.py
index b6b2bab123..819464f5bd 100644
--- a/jiuwenclaw/gateway/cron/scheduler.py
+++ b/jiuwenclaw/gateway/cron/scheduler.py
@@ -163,6 +163,9 @@ class CronSchedulerService:
self._seq += 1
ev = _Event(at_ts=at_ts, seq=self._seq, kind=kind, job_id=job_id, run_id=run_id)
heapq.heappush(self._events, (ev.at_ts, ev.seq, ev))
+ # 若事件已在 1 秒内到期(如 push_update 补发),需唤醒主循环,否则会等到 timeout(可能 10 分钟)
+ if at_ts <= self._now_fn() + 1.0:
+ self._reload_event.set()
def _compute_next_run(self, job: CronJob, *, now_ts: float) -> tuple[datetime, datetime, str]:
tz = ZoneInfo(job.timezone)
@@ -286,11 +289,25 @@ class CronSchedulerService:
state.finished_at = self._now_fn()
# if placeholder already sent, push update immediately
if state.placeholder_sent and not state.pushed_final and state.result_text:
+ logger.info(
+ "[Cron] scheduling immediate push_update after agent finished "
+ "job=%s run_id=%s text_len=%d",
+ job.id,
+ run_id,
+ len(state.result_text or ""),
+ )
self._schedule_event(datetime.fromtimestamp(self._now_fn(), tz=ZoneInfo(job.timezone)), "push_update", job.id, run_id)
# if push time already passed, also try to push update
try:
push_dt = datetime.fromisoformat(state.push_at_iso)
if push_dt.timestamp() <= self._now_fn() and not state.pushed_final and state.result_text:
+ logger.info(
+ "[Cron] scheduling late push_update because push_at<=now "
+ "job=%s run_id=%s text_len=%d",
+ job.id,
+ run_id,
+ len(state.result_text or ""),
+ )
self._schedule_event(datetime.fromtimestamp(self._now_fn(), tz=ZoneInfo(job.timezone)), "push_update", job.id, run_id)
except Exception:
pass
@@ -331,14 +348,35 @@ class CronSchedulerService:
async def _on_push_update(self, job: CronJob, run_id: str) -> None:
state = self._runs.get(run_id)
- if state is None or state.pushed_final:
+ if state is None:
+ logger.info("[Cron] push_update skipped: no state job=%s run_id=%s", job.id, run_id)
+ return
+ if state.pushed_final:
+ logger.info("[Cron] push_update skipped: already pushed_final job=%s run_id=%s", job.id, run_id)
return
if not state.result_text:
+ logger.info("[Cron] push_update skipped: empty result_text job=%s run_id=%s", job.id, run_id)
return
+ logger.info(
+ "[Cron] push_update start job=%s run_id=%s text_len=%d",
+ job.id,
+ run_id,
+ len(state.result_text or ""),
+ )
await self._push_to_targets(job, state, text=state.result_text, is_placeholder=False)
state.pushed_final = True
+ logger.info("[Cron] push_update done job=%s run_id=%s", job.id, run_id)
async def _push_to_targets(self, job: CronJob, state: CronRunState, *, text: str, is_placeholder: bool) -> None:
+ logger.info(
+ "[Cron] push_to_targets job=%s run_id=%s channel=%s is_placeholder=%s text_len=%d status=%s",
+ job.id,
+ state.run_id,
+ (job.targets or "").strip(),
+ bool(is_placeholder),
+ len(text or ""),
+ state.status,
+ )
payload_extra = {
"content": text,
"cron": {
diff --git a/jiuwenclaw/resources/config.yaml b/jiuwenclaw/resources/config.yaml
index bffa0ae23f..f60af060c1 100644
--- a/jiuwenclaw/resources/config.yaml
+++ b/jiuwenclaw/resources/config.yaml
@@ -88,7 +88,7 @@ channels:
auto_start_bridge: false
bridge_command: node scripts/whatsapp-bridge.js
bridge_workdir:
- enabled: true
+ enabled: false
browser:
# chrome_path can be a string or per-OS map.
diff --git a/jiuwenclaw/web/package-lock.json b/jiuwenclaw/web/package-lock.json
index 6899da7ed7..f567e1cceb 100644
--- a/jiuwenclaw/web/package-lock.json
+++ b/jiuwenclaw/web/package-lock.json
@@ -79,7 +79,6 @@
"integrity": "sha512-CGOfOJqWjg2qW/Mb6zNsDm+u5vFQ8DxXfbM09z69p5Z6+mE1ikP2jUXw+j42Pf1XTYED2Rni5f95npYeuwMDQA==",
"dev": true,
"license": "MIT",
- "peer": true,
"dependencies": {
"@babel/code-frame": "^7.29.0",
"@babel/generator": "^7.29.0",
@@ -1469,7 +1468,6 @@
"integrity": "sha512-m0jEgYlYz+mDJZ2+F4v8D1AyQb+QzsNqRuI7xg1VQX/KlKS0qT9r1Mo16yo5F/MtifXFgaofIFsdFMox2SxIbQ==",
"dev": true,
"license": "MIT",
- "peer": true,
"dependencies": {
"undici-types": "~7.16.0"
}
@@ -1485,7 +1483,6 @@
"resolved": "https://registry.npmjs.org/@types/react/-/react-18.3.27.tgz",
"integrity": "sha512-cisd7gxkzjBKU2GgdYrTdtQx1SORymWyaAFhaxQPK9bYO9ot3Y5OikQRvY0VYQtvwjeQnizCINJAenh/V7MK2w==",
"license": "MIT",
- "peer": true,
"dependencies": {
"@types/prop-types": "*",
"csstype": "^3.2.2"
@@ -1556,7 +1553,6 @@
"integrity": "sha512-tbsV1jPne5CkFQCgPBcDOt30ItF7aJoZL997JSF7MhGQqOeT3svWRYxiqlfA5RUdlHN6Fi+EI9bxqbdyAUZjYQ==",
"dev": true,
"license": "BSD-2-Clause",
- "peer": true,
"dependencies": {
"@typescript-eslint/scope-manager": "6.21.0",
"@typescript-eslint/types": "6.21.0",
@@ -1746,7 +1742,6 @@
"integrity": "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==",
"dev": true,
"license": "MIT",
- "peer": true,
"bin": {
"acorn": "bin/acorn"
},
@@ -1967,7 +1962,6 @@
}
],
"license": "MIT",
- "peer": true,
"dependencies": {
"baseline-browser-mapping": "^2.9.0",
"caniuse-lite": "^1.0.30001759",
@@ -2393,7 +2387,6 @@
"deprecated": "This version is no longer supported. Please see https://eslint.org/version-support for other options.",
"dev": true,
"license": "MIT",
- "peer": true,
"dependencies": {
"@eslint-community/eslint-utils": "^4.2.0",
"@eslint-community/regexpp": "^4.6.1",
@@ -3197,7 +3190,6 @@
"resolved": "https://registry.npmjs.org/jiti/-/jiti-1.21.7.tgz",
"integrity": "sha512-/imKNG4EbWNrVjoNC/1H5/9GFy+tqjGBHCaSsN+P2RnPqjsLmv6UD3Ej+Kj8nBWaRAwyk7kK5ZUc+OEatnTR3A==",
"license": "MIT",
- "peer": true,
"bin": {
"jiti": "bin/jiti.js"
}
@@ -4533,7 +4525,6 @@
}
],
"license": "MIT",
- "peer": true,
"dependencies": {
"nanoid": "^3.3.11",
"picocolors": "^1.1.1",
@@ -4726,7 +4717,6 @@
"resolved": "https://registry.npmjs.org/react/-/react-18.3.1.tgz",
"integrity": "sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==",
"license": "MIT",
- "peer": true,
"dependencies": {
"loose-envify": "^1.1.0"
},
@@ -5207,7 +5197,6 @@
"resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.4.19.tgz",
"integrity": "sha512-3ofp+LL8E+pK/JuPLPggVAIaEuhvIz4qNcf3nA1Xn2o/7fb7s/TYpHhwGDv1ZU3PkBluUVaF8PyCHcm48cKLWQ==",
"license": "MIT",
- "peer": true,
"dependencies": {
"@alloc/quick-lru": "^5.2.0",
"arg": "^5.0.2",
@@ -5306,7 +5295,6 @@
"resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.3.tgz",
"integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==",
"license": "MIT",
- "peer": true,
"engines": {
"node": ">=12"
},
@@ -5397,7 +5385,6 @@
"integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==",
"devOptional": true,
"license": "Apache-2.0",
- "peer": true,
"bin": {
"tsc": "bin/tsc",
"tsserver": "bin/tsserver"
@@ -5590,7 +5577,6 @@
"integrity": "sha512-o5a9xKjbtuhY6Bi5S3+HvbRERmouabWbyUcpXXUA1u+GNUKoROi9byOJ8M0nHbHYHkYICiMlqxkg1KkYmm25Sw==",
"dev": true,
"license": "MIT",
- "peer": true,
"dependencies": {
"esbuild": "^0.21.3",
"postcss": "^8.4.43",