53 lines
1.3 KiB
Go
53 lines
1.3 KiB
Go
package batchmetadata
|
|
|
|
import "github.com/gogf/gf/v2/errors/gerror"
|
|
|
|
const (
|
|
Console = "console"
|
|
MiniProgram = "mini_program"
|
|
API = "api"
|
|
System = "system"
|
|
Legacy = "legacy"
|
|
Unknown = 0
|
|
Single = 1
|
|
Bulk = 2
|
|
)
|
|
|
|
// NormalizeMode validates the explicit execution size supplied by the business entry point.
|
|
// Execution size is request metadata and must not be inferred from context or result counts.
|
|
func NormalizeMode(requested int) int {
|
|
if requested == Single || requested == Bulk {
|
|
return requested
|
|
}
|
|
return Unknown
|
|
}
|
|
|
|
func ValidChannel(value string) bool {
|
|
switch value {
|
|
case Console, MiniProgram, API, System, Legacy:
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
func Channel(value string) string {
|
|
if ValidChannel(value) {
|
|
return value
|
|
}
|
|
return Legacy
|
|
}
|
|
|
|
func ValidMode(value int) bool { return value >= Unknown && value <= Bulk }
|
|
|
|
// ValidateCreation rejects missing attribution for new work; historical reads
|
|
// and resumed work continue to use Channel/NormalizeMode for compatibility.
|
|
func ValidateCreation(channel string, mode int) error {
|
|
if !ValidChannel(channel) || channel == Legacy {
|
|
return gerror.New("新建批次发起渠道无效")
|
|
}
|
|
if mode != Single && mode != Bulk {
|
|
return gerror.New("新建批次必须指定单卡或批量操作规模")
|
|
}
|
|
return nil
|
|
}
|