mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-05-04 17:27:50 +08:00
Add scheduled tasks (#13470)
### What problem does this PR solve? 1. RAGFlow server will send heartbeat periodically. 2. This PR will including: - Scheduled task - API server message sending - Admin server API to receive the message. ### Type of change - [x] New Feature (non-breaking change which adds functionality) --------- Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
@ -40,9 +40,16 @@ type Config struct {
|
||||
DocEngine DocEngineConfig `mapstructure:"doc_engine"`
|
||||
RegisterEnabled int `mapstructure:"register_enabled"`
|
||||
OAuth map[string]OAuthConfig `mapstructure:"oauth"`
|
||||
Admin AdminConfig `mapstructure:"admin"`
|
||||
UserDefaultLLM UserDefaultLLMConfig `mapstructure:"user_default_llm"`
|
||||
}
|
||||
|
||||
// AdminConfig admin server configuration
|
||||
type AdminConfig struct {
|
||||
Host string `mapstructure:"host"`
|
||||
Port int `mapstructure:"http_port"`
|
||||
}
|
||||
|
||||
// UserDefaultLLMConfig user default LLM configuration
|
||||
type UserDefaultLLMConfig struct {
|
||||
DefaultModels DefaultModelsConfig `mapstructure:"default_models"`
|
||||
@ -50,19 +57,19 @@ type UserDefaultLLMConfig struct {
|
||||
|
||||
// DefaultModelsConfig default models configuration
|
||||
type DefaultModelsConfig struct {
|
||||
ChatModel ModelConfig `mapstructure:"chat_model"`
|
||||
EmbeddingModel ModelConfig `mapstructure:"embedding_model"`
|
||||
RerankModel ModelConfig `mapstructure:"rerank_model"`
|
||||
ASRModel ModelConfig `mapstructure:"asr_model"`
|
||||
ChatModel ModelConfig `mapstructure:"chat_model"`
|
||||
EmbeddingModel ModelConfig `mapstructure:"embedding_model"`
|
||||
RerankModel ModelConfig `mapstructure:"rerank_model"`
|
||||
ASRModel ModelConfig `mapstructure:"asr_model"`
|
||||
Image2TextModel ModelConfig `mapstructure:"image2text_model"`
|
||||
}
|
||||
|
||||
// ModelConfig model configuration
|
||||
type ModelConfig struct {
|
||||
Name string `mapstructure:"name"`
|
||||
APIKey string `mapstructure:"api_key"`
|
||||
BaseURL string `mapstructure:"base_url"`
|
||||
Factory string `mapstructure:"factory"`
|
||||
Name string `mapstructure:"name"`
|
||||
APIKey string `mapstructure:"api_key"`
|
||||
BaseURL string `mapstructure:"base_url"`
|
||||
Factory string `mapstructure:"factory"`
|
||||
}
|
||||
|
||||
// OAuthConfig OAuth configuration for a channel
|
||||
@ -325,6 +332,20 @@ func Init(configPath string) error {
|
||||
return fmt.Errorf("unmarshal config error: %w", err)
|
||||
}
|
||||
|
||||
// Set default values for admin configuration if not configured
|
||||
if globalConfig.Admin.Host == "" {
|
||||
globalConfig.Admin.Host = v.GetString("admin.host")
|
||||
}
|
||||
if globalConfig.Admin.Host == "" {
|
||||
globalConfig.Admin.Host = "127.0.0.1"
|
||||
}
|
||||
if globalConfig.Admin.Port == 0 {
|
||||
globalConfig.Admin.Port = v.GetInt("admin.http_port")
|
||||
}
|
||||
if globalConfig.Admin.Port == 0 {
|
||||
globalConfig.Admin.Port = 9381
|
||||
}
|
||||
|
||||
// Load REGISTER_ENABLED from environment variable (default: 1)
|
||||
registerEnabled := 1
|
||||
if envVal := os.Getenv("REGISTER_ENABLED"); envVal != "" {
|
||||
@ -357,8 +378,8 @@ func Init(configPath string) error {
|
||||
if v.IsSet("ragflow") {
|
||||
ragflowConfig := v.Sub("ragflow")
|
||||
if ragflowConfig != nil {
|
||||
globalConfig.Server.Port = ragflowConfig.GetInt("http_port") + 2 // 9382, by default
|
||||
// globalConfig.Server.Port = ragflowConfig.GetInt("http_port") // Correct
|
||||
//globalConfig.Server.Port = ragflowConfig.GetInt("http_port") + 2 // 9382, by default
|
||||
globalConfig.Server.Port = ragflowConfig.GetInt("http_port") // Correct
|
||||
// If mode is not set, default to debug
|
||||
if globalConfig.Server.Mode == "" {
|
||||
globalConfig.Server.Mode = "release"
|
||||
@ -484,6 +505,14 @@ func GetConfig() *Config {
|
||||
return globalConfig
|
||||
}
|
||||
|
||||
// GetAdminConfig gets the admin server configuration
|
||||
func GetAdminConfig() *AdminConfig {
|
||||
if globalConfig == nil {
|
||||
return nil
|
||||
}
|
||||
return &globalConfig.Admin
|
||||
}
|
||||
|
||||
// SetLogger sets the logger instance
|
||||
func SetLogger(l *zap.Logger) {
|
||||
zapLogger = l
|
||||
|
||||
Reference in New Issue
Block a user