modify: S3对象存储
This commit is contained in:
@@ -68,6 +68,25 @@ class MyPlugin(Plugin):
|
||||
# url = "postgresql+asyncpg://user:pwd@127.0.0.1:5432/mydb"
|
||||
# generate_schemas = true
|
||||
|
||||
# 对象存储接入(可选):在插件 config.toml 配置 storage 段后,
|
||||
# 基类 init_storage() 自动初始化 self.storage(S3/Minio,直连不经网关)::
|
||||
#
|
||||
# # config/workers/my_plugin/config.toml
|
||||
# [workers.config.storage]
|
||||
# endpoint = "192.168.1.10:9000" # Minio 地址 host:port(不带协议前缀)
|
||||
# access_key = "minioadmin"
|
||||
# secret_key = "minioadmin"
|
||||
# bucket = "chongming-files"
|
||||
# secure = false
|
||||
# # region = "" # 可选
|
||||
# # auto_create_bucket = true # 默认 true:启动时确保 bucket 存在
|
||||
#
|
||||
# 语义:未配置 / enabled=false → self.storage 为 None(插件自行降级);
|
||||
# 缺必填键(endpoint/access_key/secret_key/bucket)→ 启动硬失败(ValueError);
|
||||
# 连接失败 → 告警降级为 None。API 见 chongming_worker.storage.StorageClient
|
||||
# (put_file/put_bytes/get_file/get_bytes/delete/presigned_put_url/presigned_get_url
|
||||
# 及对应 async a* 版本,handler 中直接 await)。
|
||||
|
||||
# 暴露给 app lifespan 的模块级入口(bound method,签名与旧写法一致)
|
||||
plugin = MyPlugin()
|
||||
create_workers = plugin.create_workers
|
||||
@@ -89,6 +108,7 @@ cleanup = plugin.cleanup
|
||||
- **幂等**:重复 `create_workers` 只初始化一次(`asyncio.Lock` 守卫,并发调用安全)
|
||||
- **统一日志**:`logger` 自动带 `[type]` 前缀
|
||||
- **数据库**:`init_database()` 统一建库建表、记录,`cleanup` 自动 `dispose()`(SQLite 按 `db_name`;config 含 `database.url` 时走 PostgreSQL)
|
||||
- **对象存储**:`init_storage()` 按 config 的 `storage` 段初始化 `self.storage`(S3/Minio,可选),`cleanup` 自动关闭
|
||||
- **global_var**:`set_var()` / `get_var()` 统一读写插件 `global_var` 模块;`cleanup` 时自动将已发布的变量重置为 `None`,避免业务代码拿到已释放的资源
|
||||
- **后台任务**:`spawn_task()` 跟踪,`cleanup` 时自动取消并 `gather`
|
||||
- **清理钩子**:`register_cleanup()` 注册,`cleanup` 时逆序执行
|
||||
|
||||
Reference in New Issue
Block a user