Enhance company recommendation caching and pipeline integration
continuous-integration/drone/push Build is passing
continuous-integration/drone/push Build is passing
- Updated the company service to include a new method for scheduling the refresh of cached AI recommendations after the AI pipeline execution. - Introduced a new interface for managing cached recommendation refreshes, improving the separation of concerns within the service layer. - Enhanced the worker initialization to include Redis client support, allowing for better management of recommendation caching. - Added functionality to list company IDs with existing recommendation caches, ensuring efficient updates post-pipeline runs. - Implemented unit tests to validate the new recommendation refresh logic and ensure proper handling of various scenarios. This update significantly improves the handling of AI recommendations by integrating caching mechanisms with the AI pipeline, enhancing overall system performance and responsiveness.
This commit is contained in:
@@ -48,23 +48,35 @@ type Service interface {
|
||||
GetMinioStats(ctx context.Context) (ai_summarizer.PipelineMinioStatsResponse, error)
|
||||
}
|
||||
|
||||
// CachedRecommendationRefresher schedules a background refresh of company recommendation caches.
|
||||
type CachedRecommendationRefresher interface {
|
||||
ScheduleRefreshCachedAIRecommendationsAfterPipeline()
|
||||
}
|
||||
|
||||
// ScrapedDocumentMetadataSyncer persists MinIO scraped-document metadata onto tender records.
|
||||
type ScrapedDocumentMetadataSyncer interface {
|
||||
SyncScrapedDocumentsFromStorage(ctx context.Context, contractFolderID, noticePublicationID string) error
|
||||
}
|
||||
|
||||
type service struct {
|
||||
client Client
|
||||
logger logger.Logger
|
||||
metadataSyncer ScrapedDocumentMetadataSyncer
|
||||
client Client
|
||||
logger logger.Logger
|
||||
metadataSyncer ScrapedDocumentMetadataSyncer
|
||||
recommendationRefresher CachedRecommendationRefresher
|
||||
}
|
||||
|
||||
// NewService creates an AI pipeline admin service.
|
||||
func NewService(client Client, log logger.Logger, metadataSyncer ScrapedDocumentMetadataSyncer) Service {
|
||||
func NewService(
|
||||
client Client,
|
||||
log logger.Logger,
|
||||
metadataSyncer ScrapedDocumentMetadataSyncer,
|
||||
recommendationRefresher CachedRecommendationRefresher,
|
||||
) Service {
|
||||
return &service{
|
||||
client: client,
|
||||
logger: log,
|
||||
metadataSyncer: metadataSyncer,
|
||||
client: client,
|
||||
logger: log,
|
||||
metadataSyncer: metadataSyncer,
|
||||
recommendationRefresher: recommendationRefresher,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,6 +231,8 @@ func (s *service) Sync(ctx context.Context) (*ai_summarizer.PipelineSyncResponse
|
||||
return nil, fmt.Errorf("pipeline sync failed: %w", err)
|
||||
}
|
||||
|
||||
s.scheduleRecommendationRefreshAfterPipeline()
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -322,6 +336,8 @@ func (s *service) DailyRun(ctx context.Context) (*ai_summarizer.PipelineStartedR
|
||||
return nil, fmt.Errorf("pipeline daily-run failed: %w", err)
|
||||
}
|
||||
|
||||
s.scheduleRecommendationRefreshAfterPipeline()
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -340,6 +356,8 @@ func (s *service) Auto(ctx context.Context) (*ai_summarizer.PipelineStartedRespo
|
||||
return nil, fmt.Errorf("pipeline auto failed: %w", err)
|
||||
}
|
||||
|
||||
s.scheduleRecommendationRefreshAfterPipeline()
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -425,6 +443,13 @@ func (s *service) GetMinioStats(ctx context.Context) (ai_summarizer.PipelineMini
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *service) scheduleRecommendationRefreshAfterPipeline() {
|
||||
if s.recommendationRefresher == nil {
|
||||
return
|
||||
}
|
||||
s.recommendationRefresher.ScheduleRefreshCachedAIRecommendationsAfterPipeline()
|
||||
}
|
||||
|
||||
func validateTenderBatch(forms []TenderRefForm) ([]ai_summarizer.TenderRef, error) {
|
||||
if len(forms) == 0 {
|
||||
return nil, ErrEmptyTenderBatch
|
||||
|
||||
Reference in New Issue
Block a user