Skip to content

Db update auto rules limit#566

Merged
AlexCXC merged 35 commits intomasterfrom
db-update-auto-rules-limit
Nov 11, 2025
Merged

Db update auto rules limit#566
AlexCXC merged 35 commits intomasterfrom
db-update-auto-rules-limit

Conversation

@AlexCXC
Copy link
Contributor

@AlexCXC AlexCXC commented Dec 2, 2023

No description provided.

@AlexCXC AlexCXC force-pushed the db-update-auto-rules-limit branch from f5d6129 to 7d71681 Compare February 21, 2024 15:10
@AlexCXC AlexCXC force-pushed the db-update-auto-rules-limit branch from 6fab0c8 to 5a7a8a6 Compare October 27, 2025 09:04

# env
ENV_SEAFILE_CENTRAL_CONF_DIR = os.environ.get('SEAFILE_CENTRAL_CONF_DIR', '')
ENV_CCNET_CONF_PATH = os.path.join(ENV_SEAFILE_CENTRAL_CONF_DIR, 'ccnet.conf')
Copy link
Contributor

Choose a reason for hiding this comment

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

ccnet.conf 已经弃用, 这个 不需要

ccnet_db_name = ccnet_config.get('Database', 'DB', fallback='ccnet')
else:
ccnet_db_name = 'ccnet'
self.ccnet_db_name = ccnet_db_name
Copy link
Contributor

Choose a reason for hiding this comment

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

ccnet_db_name读取环境变量 SEATABLE_MYSQL_DB_CCNET_DB_NAME即可, 可以统一在 config.py 中进行定义和读取

return row.automation_rules_limit_per_month
user = ccnet_api.get_emailuser(username)
user_role = user.role
return self.roles.get(user_role, {}).get('automation_rules_limit_per_month', -1)
Copy link
Contributor

Choose a reason for hiding this comment

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

self.roles --> self.get_roles()

auto_rule_logger.info('rule %s not found', automation_rule_id)
return
if not rule:
return
Copy link
Contributor

Choose a reason for hiding this comment

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

if not rule 和上面56行一样, 可以删了

if row and row.automation_rules_limit_per_month and row.automation_rules_limit_per_month != 0:
return row.automation_rules_limit_per_month
user = ccnet_api.get_emailuser(username)
user_role = user.role
Copy link
Contributor

Choose a reason for hiding this comment

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

user_role =user.role 这里 user.role 可能为空的, 此时获取不到设置的配额。 参考 dtable-web中的get_user_role函数的写法

from dtable_events.utils import uuid_str_to_32_chars, get_dtable_owner_org_id


def can_trigger_by_dtable(dtable_uuid, db_session):
Copy link
Contributor

@r350178982 r350178982 Oct 31, 2025

Choose a reason for hiding this comment

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

这里有一种场景: 系统管理员配置 role 的调用次数 (不通过编辑后台每个用户的次数,可能用户数量比较多)。 第一次配置role 100 次, 然后用户超过了之后, 系统管理员可能会改成 200 次, 而此时按理来说应该是可以触发规则的, 但是,这个函数的里面的is_exceed字段已经写死了。 这里函数参数可以增加一个 ENABLE_PERMISSION_ROLES的字典,直接可以用。

if limit < 0:
return
usage, has_sent_warning = self.get_user_usage(db_session, username)
if usage >= limit:
Copy link
Contributor

Choose a reason for hiding this comment

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

这里最好也需要判断一下是否 has_sent_warning, 如果没有的话, 发送一个消息。 有一种情况, 比如我设置limit为3, 第一次触发33%, 第二次触发 66%, 第三次触发直接100%并且设置is_exceed了return了。 不会经过usage >= limit * 0.9下面发送通知。 这样逻辑会完备一点

@AlexCXC AlexCXC force-pushed the db-update-auto-rules-limit branch from 98c7462 to b15c3a9 Compare November 4, 2025 02:27
@AlexCXC AlexCXC force-pushed the db-update-auto-rules-limit branch from ffac0de to 1704a28 Compare November 7, 2025 07:03
@AlexCXC AlexCXC merged commit fa4a7f9 into master Nov 11, 2025
1 check passed
@AlexCXC AlexCXC deleted the db-update-auto-rules-limit branch November 11, 2025 08:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants