WIP: image processing is back and working

This commit is contained in:
2025-09-21 22:07:56 +01:00
parent 013447fa90
commit 1fb9616aa7
11 changed files with 54 additions and 31 deletions

View File

@@ -5,6 +5,7 @@ import (
"screenmark/screenmark/.gen/haystack/haystack/model"
"screenmark/screenmark/agents"
"screenmark/screenmark/agents/client"
"screenmark/screenmark/limits"
"screenmark/screenmark/models"
"sync"
@@ -18,7 +19,7 @@ type ImageProcessor struct {
logger *log.Logger
descriptionAgent agents.DescriptionAgent
listAgent client.AgentClient
stackAgent client.AgentClient
// TODO: add the notifier here
@@ -26,12 +27,7 @@ type ImageProcessor struct {
}
func (p *ImageProcessor) setImageToProcess(ctx context.Context, image model.Image) {
updatedImage := model.Image{
ID: image.ID,
Status: model.Progress_InProgress,
}
_, err := p.imageModel.Update(ctx, updatedImage)
err := p.imageModel.UpdateProcess(ctx, image.ID, model.Progress_InProgress)
if err != nil {
// TODO: what can we actually do here for the errors?
// We can't stop the work for the others
@@ -56,7 +52,7 @@ func (p *ImageProcessor) describe(ctx context.Context, image model.Image) {
}
func (p *ImageProcessor) extractInfo(ctx context.Context, image model.Image) {
err := p.listAgent.RunAgent(*image.UserID, image.ID, image.ImageName, image.Image)
err := p.stackAgent.RunAgent(image.UserID, image.ID, image.ImageName, image.Image)
if err != nil {
// Again, wtf do we do?
// Although i think the agent actually returns an error when it's finished
@@ -88,8 +84,16 @@ func (p *ImageProcessor) processImage(image model.Image) {
wg.Wait()
}
func NewImageProcessor(logger *log.Logger, imageModel models.ImageModel) ImageProcessor {
imageProcessor := ImageProcessor{imageModel: imageModel, logger: logger}
func NewImageProcessor(logger *log.Logger, imageModel models.ImageModel, listModel models.StackModel, limitsManager limits.LimitsManagerMethods) ImageProcessor {
descriptionAgent := agents.NewDescriptionAgent(logger, imageModel)
stackAgent := agents.NewListAgent(logger, listModel, limitsManager)
imageProcessor := ImageProcessor{
imageModel: imageModel,
logger: logger,
descriptionAgent: descriptionAgent,
stackAgent: stackAgent,
}
imageProcessor.Processor = NewProcessor(int(IMAGE_PROCESS_AT_A_TIME), imageProcessor.processImage)