feat: sync deployed v1.0.0-rc.38-custom.42
Publish Docker image (Multi-arch) / Build & push (amd64) (push) Failing after 1m40s
Release (Linux, macOS, Windows) / Linux Release (push) Failing after 42m16s
Publish Docker image (Multi-arch) / Build & push (arm64) (push) Canceled after 0s
Release (Linux, macOS, Windows) / macOS Release (push) Canceled after 0s
Release (Linux, macOS, Windows) / Windows Release (push) Canceled after 0s
Publish Docker image (Multi-arch) / Create multi-arch manifests (push) Canceled after 0s

Sync production source including routing, billing, Astra detection and public uptime. Update custom build instructions and license packaging.
This commit is contained in:
cneicy committed 2026-09-26 04:49:11 +08:00
1 parent c2b44332d6
commit a5f7b8e586
828 files changed
+122253 -13702

No files matched your search

+72
View File
@@ -3,6 +3,7 @@ package controller
import (
"context"
"fmt"
"sync"
"time"
"github.com/QuantumNous/new-api/common"
@@ -18,6 +19,9 @@ import (
// instances and each run is recorded as one task row. Call this before
// service.StartSystemTaskRunner.
func RegisterScheduledSystemTasks() {
service.RegisterSystemTaskHandler(detectionHandler{})
service.RegisterSystemTaskHandler(astraSamplingHandler{})
service.RegisterSystemTaskHandler(channelAvailabilityHandler{})
service.RegisterSystemTaskHandler(channelTestHandler{})
service.RegisterSystemTaskHandler(modelUpdateHandler{})
service.RegisterSystemTaskHandler(midjourneyPollHandler{})
@@ -29,6 +33,74 @@ func RegisterScheduledSystemTasks() {
// into the system task runner.
type channelTestHandler struct{}
type channelAvailabilityHandler struct{}
func (channelAvailabilityHandler) Type() string { return model.SystemTaskTypeChannelAvailability }
func (channelAvailabilityHandler) Enabled() bool { return service.AstraAvailabilityEnabled() }
func (channelAvailabilityHandler) Interval() time.Duration {
return time.Duration(service.AstraAvailabilityIntervalMinutes()) * time.Minute
}
func (channelAvailabilityHandler) ScheduleFromCreation() bool { return true }
func (channelAvailabilityHandler) NewPayload() any { return nil }
func (channelAvailabilityHandler) Run(ctx context.Context, task *model.SystemTask, runnerID string) {
testUserID, err := resolveChannelTestUserID(nil)
if err != nil {
finishSystemTaskHandler(task, runnerID, model.SystemTaskStatusFailed, nil, err)
return
}
channels, err := model.GetAllChannels(0, 0, true, false)
if err != nil {
finishSystemTaskHandler(task, runnerID, model.SystemTaskStatusFailed, nil, err)
return
}
selected := make([]*model.Channel, 0, len(channels))
for _, channel := range channels {
if channel.Status == common.ChannelStatusEnabled {
selected = append(selected, channel)
}
}
settings := operation_setting.GetMonitorSetting()
state := service.ChannelAvailabilityState{Rounds: []service.ChannelAvailabilityRound{}}
var mu sync.Mutex
var persistErr error
ctx, cancel := context.WithCancel(ctx)
defer cancel()
disableThreshold := int64(common.ChannelDisableThreshold * 1000)
if disableThreshold == 0 {
disableThreshold = 10000000
}
summary := runChannelTestWorkers(ctx, selected, settings.ChannelTestConcurrency, func(ctx context.Context, channel *model.Channel) channelTestSummary {
result := testChannelForHealthCheck(ctx, channel, testUserID, false, disableThreshold)
if result.Tested == 0 {
return result
}
mu.Lock()
defer mu.Unlock()
if persistErr == nil {
state.Rounds = append(state.Rounds, service.ChannelAvailabilityRound{ChannelID: channel.Id, At: time.Now().Unix(), Success: result.Succeeded == 1})
persistErr = model.UpdateSystemTaskState(task.TaskID, runnerID, state)
if persistErr != nil {
cancel()
}
}
return result
}, nil)
if persistErr != nil {
finishSystemTaskHandler(task, runnerID, model.SystemTaskStatusFailed, summary, persistErr)
return
}
if ctx.Err() != nil {
finishSystemTaskHandler(task, runnerID, model.SystemTaskStatusFailed, summary, ctx.Err())
return
}
finishSystemTaskHandler(task, runnerID, model.SystemTaskStatusSucceeded, summary, nil)
}
func (channelTestHandler) Type() string { return model.SystemTaskTypeChannelTest }
func (channelTestHandler) Enabled() bool {