Files
ragflow/internal/server/local/admin_status.go
Jin Hai 7ebe1d2722 Fix docker building (#13681)
### What problem does this PR solve?

1. Refactor go server log
2. Update docker building, since nginx config should be set according to
the deployment.

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)

---------

Signed-off-by: Jin Hai <haijin.chn@gmail.com>
2026-03-19 10:25:35 +08:00

86 lines
2.2 KiB
Go

//
// Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package local
import (
"fmt"
"ragflow/internal/logger"
"sync"
)
// AdminStatus represents the admin status
// 0 = valid, 1 = invalid
type AdminStatus struct {
Status int `json:"status"` // 0 = available, 1 = not available
Reason string `json:"reason"` // reason for invalid status
}
var (
adminStatus *AdminStatus
adminStatusMu sync.RWMutex
adminStatusOnce sync.Once
)
// InitAdminStatus initializes the global admin status
// status: 0 = valid, 1 = invalid (default)
func InitAdminStatus(status int, reason string) {
adminStatusOnce.Do(func() {
adminStatus = &AdminStatus{
Status: status,
Reason: reason,
}
})
}
// GetAdminStatus returns the current admin status
func GetAdminStatus() AdminStatus {
adminStatusMu.RLock()
defer adminStatusMu.RUnlock()
if adminStatus == nil {
return AdminStatus{Status: 1, Reason: "not initialized"}
}
return AdminStatus{
Status: adminStatus.Status,
Reason: adminStatus.Reason,
}
}
// SetAdminStatus updates the admin status
func SetAdminStatus(status int, reason string) {
adminStatusMu.Lock()
defer adminStatusMu.Unlock()
if adminStatus == nil {
adminStatus = &AdminStatus{}
}
adminStatus.Status = status
adminStatus.Reason = reason
if adminStatus.Status != 0 {
logger.Warn(fmt.Sprintf("Admin server is unavailable, reason: %s", adminStatus.Reason))
}
}
// IsAdminAvailable returns true if admin is valid (Status == 0)
func IsAdminAvailable() bool {
adminStatusMu.RLock()
defer adminStatusMu.RUnlock()
if adminStatus == nil {
return false
}
return adminStatus.Status == 0
}