schema_provider.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package tasks
  2. import (
  3. "sync"
  4. "github.com/seaweedfs/seaweedfs/weed/admin/config"
  5. )
  6. // TaskConfigSchema defines the schema for task configuration
  7. type TaskConfigSchema struct {
  8. config.Schema // Embed common schema functionality
  9. TaskName string `json:"task_name"`
  10. DisplayName string `json:"display_name"`
  11. Description string `json:"description"`
  12. Icon string `json:"icon"`
  13. }
  14. // TaskConfigSchemaProvider is an interface for providing task configuration schemas
  15. type TaskConfigSchemaProvider interface {
  16. GetConfigSchema() *TaskConfigSchema
  17. }
  18. // schemaRegistry maintains a registry of schema providers by task type
  19. type schemaRegistry struct {
  20. providers map[string]TaskConfigSchemaProvider
  21. mutex sync.RWMutex
  22. }
  23. var globalSchemaRegistry = &schemaRegistry{
  24. providers: make(map[string]TaskConfigSchemaProvider),
  25. }
  26. // RegisterTaskConfigSchema registers a schema provider for a task type
  27. func RegisterTaskConfigSchema(taskType string, provider TaskConfigSchemaProvider) {
  28. globalSchemaRegistry.mutex.Lock()
  29. defer globalSchemaRegistry.mutex.Unlock()
  30. globalSchemaRegistry.providers[taskType] = provider
  31. }
  32. // GetTaskConfigSchema returns the schema for the specified task type
  33. func GetTaskConfigSchema(taskType string) *TaskConfigSchema {
  34. globalSchemaRegistry.mutex.RLock()
  35. provider, exists := globalSchemaRegistry.providers[taskType]
  36. globalSchemaRegistry.mutex.RUnlock()
  37. if !exists {
  38. return nil
  39. }
  40. return provider.GetConfigSchema()
  41. }