Refactor AI pipeline handling to support daily runs
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.
This commit is contained in:
Mazyar
2026-07-07 12:17:03 +03:30
parent 89faa08b1c
commit 1ad0206e61
5 changed files with 92 additions and 88 deletions
-56
View File
@@ -1,56 +0,0 @@
package workers
import (
"context"
"errors"
"time"
"tm/pkg/ai_summarizer"
"tm/pkg/logger"
)
// AIPipelineAutoWorker triggers the Opplens AI pipeline auto run (sync + complete missing work).
type AIPipelineAutoWorker struct {
Logger logger.Logger
AIClient *ai_summarizer.Client
}
// NewAIPipelineAutoWorker creates a worker that calls POST /pipeline/auto on the AI service.
func NewAIPipelineAutoWorker(log logger.Logger, aiClient *ai_summarizer.Client) *AIPipelineAutoWorker {
return &AIPipelineAutoWorker{
Logger: log,
AIClient: aiClient,
}
}
// Run starts the pipeline auto job. A 409 response means a run is already in progress and is not an error.
func (w *AIPipelineAutoWorker) Run() error {
if w.AIClient == nil {
w.Logger.Warn("AI pipeline auto 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 auto worker started", map[string]interface{}{})
resp, err := w.AIClient.PipelineAuto(ctx)
if err != nil {
if errors.Is(err, ai_summarizer.ErrPipelineJobRunning) {
w.Logger.Info("AI pipeline auto skipped: job already running", map[string]interface{}{})
return nil
}
w.Logger.Error("AI pipeline auto worker failed", map[string]interface{}{
"error": err.Error(),
})
return err
}
w.Logger.Info("AI pipeline auto worker triggered successfully", map[string]interface{}{
"status": resp.Status,
"report": resp.Report,
})
return nil
}
+52
View File
@@ -0,0 +1,52 @@
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
}