From eead4b05d834ba6d7de4f67f8dd61d2d16724bac Mon Sep 17 00:00:00 2001 From: "n.nakhostin" Date: Mon, 20 Oct 2025 11:32:50 +0330 Subject: [PATCH] Refactor Worker Initialization to Remove Ollama SDK Dependency - Removed the Ollama SDK from the worker initialization process, simplifying the worker's dependencies and enhancing maintainability. - Updated the InitWorker function and NewNoticeWorker constructor to reflect the removal of the Ollama SDK, ensuring a cleaner and more focused implementation. - Commented out the Ollama model listing logic for potential future use, maintaining clarity in the main function while reducing unnecessary complexity. --- cmd/worker/bootstrap/bootstrap.go | 6 +++--- cmd/worker/main.go | 18 +++++++++--------- cmd/worker/workers/notice.go | 3 +-- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/cmd/worker/bootstrap/bootstrap.go b/cmd/worker/bootstrap/bootstrap.go index 844ac09..9452de6 100644 --- a/cmd/worker/bootstrap/bootstrap.go +++ b/cmd/worker/bootstrap/bootstrap.go @@ -74,19 +74,19 @@ func InitMongoDB(conf config.MongoConfig, log logger.Logger) *mongo.ConnectionMa } // Init Worker -func InitWorker(config Config, mongoManager *mongo.ConnectionManager, appLogger logger.Logger, notify notification.SDK, ollamaSDK *ollama.SDK) { +func InitWorker(config Config, mongoManager *mongo.ConnectionManager, appLogger logger.Logger, notify notification.SDK) { // Initialize repositories noticeRepo := notice.NewRepository(mongoManager, appLogger) tenderRepo := tender.NewRepository(mongoManager, appLogger) - worker := workers.NewNoticeWorker(mongoManager, appLogger, notify, noticeRepo, tenderRepo, ollamaSDK) + worker := workers.NewNoticeWorker(mongoManager, appLogger, notify, noticeRepo, tenderRepo) worker.Run() // start Worker job schedule.NewCronScheduler(appLogger, mongoManager, noticeRepo).AddJob(schedule.Job{ Name: "Worker Job", Func: func() { - worker := workers.NewNoticeWorker(mongoManager, appLogger, notify, noticeRepo, tenderRepo, ollamaSDK) + worker := workers.NewNoticeWorker(mongoManager, appLogger, notify, noticeRepo, tenderRepo) worker.Run() }, Expr: config.Worker.Interval, diff --git a/cmd/worker/main.go b/cmd/worker/main.go index e01131e..18cb77b 100644 --- a/cmd/worker/main.go +++ b/cmd/worker/main.go @@ -38,17 +38,17 @@ func main() { notificationService := bootstrap.InitNotificationService(config.Notification, appLogger) // Initialize ollama service - ollamaSDK := bootstrap.InitOllamaService(config.Ollama, appLogger) - aiModels, err := ollamaSDK.ListModels(context.Background()) - if err != nil { - appLogger.Error("Failed to list ollama models", map[string]interface{}{ - "error": err.Error(), - }) - } - appLogger.Info("Ollama models", map[string]interface{}{"models": aiModels}) + // ollamaSDK := bootstrap.InitOllamaService(config.Ollama, appLogger) + // aiModels, err := ollamaSDK.ListModels(context.Background()) + // if err != nil { + // appLogger.Error("Failed to list ollama models", map[string]interface{}{ + // "error": err.Error(), + // }) + // } + // appLogger.Info("Ollama models", map[string]interface{}{"models": aiModels}) // Initialize Worker - bootstrap.InitWorker(*config, mongoManager, appLogger, notificationService, ollamaSDK) + bootstrap.InitWorker(*config, mongoManager, appLogger, notificationService) // Set up signal handling for graceful shutdown signalChan := make(chan os.Signal, 1) diff --git a/cmd/worker/workers/notice.go b/cmd/worker/workers/notice.go index a9e7d82..4274386 100644 --- a/cmd/worker/workers/notice.go +++ b/cmd/worker/workers/notice.go @@ -19,12 +19,11 @@ type NoticeWorker struct { TenderRepo tender.TenderRepository } -func NewNoticeWorker(mongo *mongo.ConnectionManager, logger logger.Logger, notify notification.SDK, noticeRepo notice.Repository, tenderRepo tender.TenderRepository, ollama *ollama.SDK) *NoticeWorker { +func NewNoticeWorker(mongo *mongo.ConnectionManager, logger logger.Logger, notify notification.SDK, noticeRepo notice.Repository, tenderRepo tender.TenderRepository) *NoticeWorker { return &NoticeWorker{ Mongo: mongo, Logger: logger, Notify: notify, - Ollama: ollama, NoticeRepo: noticeRepo, TenderRepo: tenderRepo, }