实现七月迭代公共技术基础
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 9m20s
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 9m20s
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
package constants
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/pkg/asynctask"
|
||||
)
|
||||
|
||||
// Fiber Locals 的上下文键
|
||||
const (
|
||||
@@ -79,6 +83,7 @@ const (
|
||||
TaskTypeAlertCheck = "alert:check" // 告警检查
|
||||
TaskTypeDataCleanup = "data:cleanup" // 数据清理
|
||||
TaskTypeDailyTrafficFlush = "traffic:daily:flush" // 每日流量落盘
|
||||
TaskTypeOutboxDeliver = "outbox:deliver" // 公共 Outbox 事件投递
|
||||
)
|
||||
|
||||
// 用户状态常量
|
||||
@@ -219,6 +224,7 @@ const (
|
||||
QueueAlertCheck = TaskTypeAlertCheck // 告警检查任务队列
|
||||
QueueDataCleanup = TaskTypeDataCleanup // 数据清理任务队列
|
||||
QueueDailyTrafficFlush = TaskTypeDailyTrafficFlush // 每日流量落盘任务队列
|
||||
QueueOutboxDeliver = TaskTypeOutboxDeliver // 公共 Outbox 投递队列
|
||||
|
||||
DefaultRetryMax = 5 // 默认任务最大重试次数
|
||||
DefaultTimeout = 10 * time.Minute // 默认任务超时时间
|
||||
@@ -276,6 +282,8 @@ func QueueForTaskType(taskType string) string {
|
||||
return QueueDataCleanup
|
||||
case TaskTypeDailyTrafficFlush:
|
||||
return QueueDailyTrafficFlush
|
||||
case TaskTypeOutboxDeliver:
|
||||
return QueueOutboxDeliver
|
||||
default:
|
||||
return QueueDefault
|
||||
}
|
||||
@@ -309,6 +317,7 @@ func DefaultTaskQueueWeights() map[string]int {
|
||||
QueuePackageDataReset: 1,
|
||||
QueueDataCleanup: 1,
|
||||
QueueDailyTrafficFlush: 1,
|
||||
QueueOutboxDeliver: 4,
|
||||
QueueDefault: 1,
|
||||
QueueLow: 1,
|
||||
}
|
||||
@@ -329,11 +338,11 @@ const (
|
||||
|
||||
// 导出主任务状态常量
|
||||
const (
|
||||
ExportTaskStatusPending = 1 // 待处理
|
||||
ExportTaskStatusProcessing = 2 // 处理中
|
||||
ExportTaskStatusCompleted = 3 // 已完成
|
||||
ExportTaskStatusFailed = 4 // 已失败
|
||||
ExportTaskStatusCancelled = 5 // 已取消
|
||||
ExportTaskStatusPending = asynctask.StatusPending // 待处理
|
||||
ExportTaskStatusProcessing = asynctask.StatusProcessing // 处理中
|
||||
ExportTaskStatusCompleted = asynctask.StatusCompleted // 已完成
|
||||
ExportTaskStatusFailed = asynctask.StatusFailed // 已失败
|
||||
ExportTaskStatusCancelled = asynctask.StatusCancelled // 已取消
|
||||
)
|
||||
|
||||
// 导出分片任务状态常量
|
||||
@@ -450,20 +459,11 @@ func GetShelfStatusName(status int) string {
|
||||
|
||||
// GetExportTaskStatusName 获取导出主任务状态名称
|
||||
func GetExportTaskStatusName(status int) string {
|
||||
switch status {
|
||||
case ExportTaskStatusPending:
|
||||
return "待处理"
|
||||
case ExportTaskStatusProcessing:
|
||||
return "处理中"
|
||||
case ExportTaskStatusCompleted:
|
||||
return "已完成"
|
||||
case ExportTaskStatusFailed:
|
||||
return "已失败"
|
||||
case ExportTaskStatusCancelled:
|
||||
return "已取消"
|
||||
default:
|
||||
name := asynctask.StatusName(status)
|
||||
if name == "" {
|
||||
return "未知"
|
||||
}
|
||||
return name
|
||||
}
|
||||
|
||||
// GetExportShardStatusName 获取导出分片任务状态名称
|
||||
|
||||
45
pkg/constants/outbox.go
Normal file
45
pkg/constants/outbox.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package constants
|
||||
|
||||
import "time"
|
||||
|
||||
const (
|
||||
// OutboxStatusPending 表示事件待投递。
|
||||
OutboxStatusPending = 1
|
||||
// OutboxStatusDelivering 表示事件已被 Relay 租约领取。
|
||||
OutboxStatusDelivering = 2
|
||||
// OutboxStatusDelivered 表示事件已成功提交到队列。
|
||||
OutboxStatusDelivered = 3
|
||||
// OutboxStatusFailed 表示事件达到最终失败或等待人工重放。
|
||||
OutboxStatusFailed = 4
|
||||
)
|
||||
|
||||
const (
|
||||
// OutboxDefaultMaxRetries 是公共 Outbox 默认最大重试次数。
|
||||
OutboxDefaultMaxRetries = 10
|
||||
// OutboxDefaultLeaseDuration 是 Relay 默认租约时长。
|
||||
OutboxDefaultLeaseDuration = time.Minute
|
||||
// OutboxDefaultBatchSize 是 Relay 默认单批领取数。
|
||||
OutboxDefaultBatchSize = 100
|
||||
// OutboxBaseRetryDelay 是瞬时失败指数退避的基础时长。
|
||||
OutboxBaseRetryDelay = 5 * time.Second
|
||||
// OutboxMaxRetryDelay 是瞬时失败指数退避的上限。
|
||||
OutboxMaxRetryDelay = 30 * time.Minute
|
||||
// OutboxRelayPollInterval 是 Worker 扫描到期事件的默认间隔。
|
||||
OutboxRelayPollInterval = time.Second
|
||||
)
|
||||
|
||||
// GetOutboxStatusName 返回 Outbox 内部状态中文名称。
|
||||
func GetOutboxStatusName(status int) string {
|
||||
switch status {
|
||||
case OutboxStatusPending:
|
||||
return "待投递"
|
||||
case OutboxStatusDelivering:
|
||||
return "投递中"
|
||||
case OutboxStatusDelivered:
|
||||
return "已投递"
|
||||
case OutboxStatusFailed:
|
||||
return "投递失败"
|
||||
default:
|
||||
return "未知"
|
||||
}
|
||||
}
|
||||
24
pkg/constants/system_config.go
Normal file
24
pkg/constants/system_config.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package constants
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
// SystemConfigTypeString 表示字符串配置。
|
||||
SystemConfigTypeString = "string"
|
||||
// SystemConfigTypeInt 表示整数配置。
|
||||
SystemConfigTypeInt = "int"
|
||||
// SystemConfigTypeBool 表示布尔配置。
|
||||
SystemConfigTypeBool = "bool"
|
||||
// SystemConfigTypeJSON 表示 JSON 配置。
|
||||
SystemConfigTypeJSON = "json"
|
||||
// SystemConfigCacheTTL 是系统配置默认缓存时长。
|
||||
SystemConfigCacheTTL = 5 * time.Minute
|
||||
)
|
||||
|
||||
// RedisSystemConfigKey 生成单个系统配置的 Redis 缓存键。
|
||||
func RedisSystemConfigKey(configKey string) string {
|
||||
return fmt.Sprintf("system_config:value:%s", configKey)
|
||||
}
|
||||
Reference in New Issue
Block a user