Files
TaskPool/internal/router/register.go
T
2025-12-22 16:05:07 +08:00

51 lines
1.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package router
import (
"baihu/internal/constant"
"baihu/internal/controllers"
"baihu/internal/services"
)
var cronService *services.CronService
func RegisterControllers() *Controllers {
// Initialize services
settingsService := services.NewSettingsService()
loginLogService := services.NewLoginLogService()
// 执行系统初始化(返回 userService
initService := services.NewInitService(settingsService)
userService := initService.Initialize()
taskService := services.NewTaskService()
envService := services.NewEnvService()
scriptService := services.NewScriptService()
executorService := services.NewExecutorService(taskService)
// Initialize cron service
cronService = services.NewCronService(taskService, executorService)
cronService.Start()
// Initialize and return controllers
return &Controllers{
Task: controllers.NewTaskController(taskService, cronService),
Auth: controllers.NewAuthController(userService, settingsService, loginLogService),
Env: controllers.NewEnvController(envService),
Script: controllers.NewScriptController(scriptService),
Executor: controllers.NewExecutorController(executorService),
File: controllers.NewFileController(constant.ScriptsWorkDir),
Dashboard: controllers.NewDashboardController(cronService, executorService),
Log: controllers.NewLogController(),
Terminal: controllers.NewTerminalController(),
Settings: controllers.NewSettingsController(userService, loginLogService, executorService),
Runtime: controllers.NewRuntimeController(),
}
}
// StopCron stops the cron service gracefully
func StopCron() {
if cronService != nil {
cronService.Stop()
}
}