Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions dtable_events/automations/automations_stats_manager.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
from datetime import date
from datetime import date, timedelta
from types import SimpleNamespace

from sqlalchemy import text
Expand Down Expand Up @@ -154,8 +154,8 @@ def update_stats(self, db_session, auto_rule_result: AutomationResult):
UPDATE dtable_automation_rules SET last_trigger_time=:trigger_time, is_valid=:is_valid, trigger_count=trigger_count+1 WHERE id=:rule_id;
'''
insert_rule_log = '''
INSERT INTO auto_rules_task_log (trigger_time, success, rule_id, run_condition, dtable_uuid, org_id, owner, warnings) VALUES
(:trigger_time, :success, :rule_id, :run_condition, :dtable_uuid, :org_id, :owner, :warnings)
INSERT INTO auto_rules_task_log (trigger_time, end_time, success, rule_id, run_condition, dtable_uuid, org_id, owner, warnings) VALUES

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Critical] 缺少数据库升级脚本

Why this matters:
现有 SeaTable 部署的 auto_rules_task_log 尚无 end_time 列,而这里会在每次自动化完成时执行包含该列的 INSERT,导致 MySQL 报“Unknown column”,统计更新和日志写入都会回滚。配套 dtable-web PR 也没有更新初始建表 SQL,因此新安装同样不具备该列。

Suggested fix: 在 dtable-web 的对应版本升级 SQL 中增加可重复执行的 ALTER TABLE auto_rules_task_log ADD COLUMN ... end_time DATETIME(6) NULL,并同步更新 sql/mysql.sql 的建表定义;部署 dtable-events 前必须先执行该迁移。

(:trigger_time, :end_time, :success, :rule_id, :run_condition, :dtable_uuid, :org_id, :owner, :warnings)
'''
org_id = auto_rule_result.org_id
owner = auto_rule_result.owner
Expand All @@ -179,6 +179,7 @@ def update_stats(self, db_session, auto_rule_result: AutomationResult):
'owner': auto_rule_result.owner,
'trigger_time': auto_rule_result.trigger_time,
'trigger_date': auto_rule_result.trigger_date,
'end_time': auto_rule_result.trigger_time + timedelta(seconds=auto_rule_result.run_time),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Warning] 新增时间计算缺少回归覆盖

Why this matters:
这里新增了 end_time 的计算并作为 INSERT 参数写库,但本 PR 没有覆盖 update_stats() 的测试。小数秒、资源限流产生的 run_time=0 或参数绑定回归都会在异步统计链路中静默影响记录。

Suggested fix: 为 AutomationsStatsManager.update_stats() 添加 mock session 单测,断言 end_time == trigger_time + timedelta(seconds=run_time),并覆盖小数秒、零耗时和 SQL 实际携带 :end_time

'is_valid': auto_rule_result.is_valid,
'success': 1 if auto_rule_result.success else 0,
'run_condition': auto_rule_result.run_condition,
Expand Down
Loading