492f9ba3c8
continuous-integration/drone/push Build is passing
- Introduced AIPipelineAutoWorker to manage the execution of the AI pipeline auto run, including startup catch-up and scheduled tasks. - Enhanced WorkerConfig to include AIPipelineAutoEnabled and AIPipelineAutoInterval settings for better control over AI pipeline execution. - Added logging for AI pipeline auto run status, including success and error handling, to improve observability. - Updated daily job tracker to include AIPipelineAutoJobName for tracking AI pipeline job completions. This update enhances the system's capability to automate AI pipeline executions, improving efficiency and reliability in processing AI tasks.
57 lines
1.5 KiB
Go
57 lines
1.5 KiB
Go
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
|
|
}
|