Implement Worker Service and Refactor Tender Initialization
- Introduced a new worker service with a dedicated main entry point for handling background tasks, including MongoDB connection management and notification service initialization. - Added a bootstrap package to manage application configuration, logging, and service initialization for the worker. - Implemented a NoticeWorker to process unprocessed notices and create corresponding tender entities, enhancing the integration of notice management within the tender system. - Refactored the tender service to remove the Ollama SDK dependency, streamlining the service initialization in the main application. - Enhanced the notice repository with a method to retrieve unprocessed notices, improving data handling capabilities.
This commit is contained in:
@@ -15,6 +15,7 @@ type Repository interface {
|
||||
BulkImport(ctx context.Context, notices []Notice) error
|
||||
GetByID(ctx context.Context, id string) (*Notice, error)
|
||||
GetByContractNoticeID(ctx context.Context, contractNoticeID string) (*Notice, error)
|
||||
GetUnProcessedNotices(ctx context.Context, limit int, skip int) ([]Notice, int64, error)
|
||||
Delete(ctx context.Context, id string) error
|
||||
}
|
||||
|
||||
@@ -121,6 +122,27 @@ func (r *noticeRepository) GetByContractNoticeID(ctx context.Context, contractNo
|
||||
return &result.Items[0], nil
|
||||
}
|
||||
|
||||
// GetUnProcessedNotices retrieves unprocessed notices
|
||||
|
||||
func (r *noticeRepository) GetUnProcessedNotices(ctx context.Context, limit int, skip int) ([]Notice, int64, error) {
|
||||
filter := bson.M{"processing_metadata.processed": false}
|
||||
|
||||
pagination := orm.Pagination{
|
||||
Limit: limit,
|
||||
Skip: skip,
|
||||
}
|
||||
|
||||
result, err := r.ormRepo.FindAll(ctx, filter, pagination)
|
||||
if err != nil {
|
||||
r.logger.Error("Failed to get unprocessed notices", map[string]interface{}{
|
||||
"error": err.Error(),
|
||||
})
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
return result.Items, result.TotalCount, nil
|
||||
}
|
||||
|
||||
// Update updates an existing notice
|
||||
func (r *noticeRepository) Update(ctx context.Context, notice *Notice) error {
|
||||
notice.UpdatedAt = time.Now().Unix()
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"time"
|
||||
"tm/internal/company"
|
||||
"tm/pkg/logger"
|
||||
"tm/pkg/ollama"
|
||||
"tm/pkg/response"
|
||||
)
|
||||
|
||||
@@ -28,16 +27,14 @@ type Service interface {
|
||||
type tenderService struct {
|
||||
repository TenderRepository
|
||||
companyService company.Service
|
||||
ollamaSDK ollama.SDK
|
||||
logger logger.Logger
|
||||
}
|
||||
|
||||
// NewService creates a new tender service
|
||||
func NewService(repository TenderRepository, companyService company.Service, ollamaSDK ollama.SDK, logger logger.Logger) Service {
|
||||
func NewService(repository TenderRepository, companyService company.Service, logger logger.Logger) Service {
|
||||
return &tenderService{
|
||||
repository: repository,
|
||||
companyService: companyService,
|
||||
ollamaSDK: ollamaSDK,
|
||||
logger: logger,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user