1ad0206e61
continuous-integration/drone/push Build is passing
- Renamed and refactored the AI pipeline auto run functionality to a daily run, enhancing clarity and purpose. - Introduced a new `AIPipelineDailyWorker` to manage the daily execution of the AI pipeline, replacing the previous auto run implementation. - Updated configuration fields and logging messages to reflect the change from auto to daily run, ensuring consistent terminology throughout the codebase. - Removed the obsolete `ai_pipeline_auto.go` file to streamline the worker structure. This update improves the maintainability and readability of the AI pipeline management by clearly distinguishing between auto and daily run functionalities.
53 lines
1.5 KiB
Go
53 lines
1.5 KiB
Go
package workers
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"tm/pkg/ai_summarizer"
|
|
"tm/pkg/logger"
|
|
)
|
|
|
|
// AIPipelineDailyWorker triggers the Opplens AI pipeline daily run (sync + full pipeline on newly synced tenders).
|
|
type AIPipelineDailyWorker struct {
|
|
Logger logger.Logger
|
|
AIClient *ai_summarizer.Client
|
|
}
|
|
|
|
// NewAIPipelineDailyWorker creates a worker that calls POST /pipeline/daily-run on the AI service.
|
|
func NewAIPipelineDailyWorker(log logger.Logger, aiClient *ai_summarizer.Client) *AIPipelineDailyWorker {
|
|
return &AIPipelineDailyWorker{
|
|
Logger: log,
|
|
AIClient: aiClient,
|
|
}
|
|
}
|
|
|
|
// Run starts the pipeline daily-run job. A 409 response means a run is already in progress and is returned as an error
|
|
// so the daily job tracker does not mark today as completed before the run actually starts.
|
|
func (w *AIPipelineDailyWorker) Run() error {
|
|
if w.AIClient == nil {
|
|
w.Logger.Warn("AI pipeline daily worker skipped: AI client is not configured", map[string]interface{}{})
|
|
return nil
|
|
}
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
|
|
defer cancel()
|
|
|
|
w.Logger.Info("AI pipeline daily worker started", map[string]interface{}{})
|
|
|
|
resp, err := w.AIClient.PipelineDailyRun(ctx)
|
|
if err != nil {
|
|
w.Logger.Error("AI pipeline daily worker failed", map[string]interface{}{
|
|
"error": err.Error(),
|
|
})
|
|
return err
|
|
}
|
|
|
|
w.Logger.Info("AI pipeline daily worker triggered successfully", map[string]interface{}{
|
|
"status": resp.Status,
|
|
"report": resp.Report,
|
|
})
|
|
|
|
return nil
|
|
}
|