Skip to content

Commit

Permalink
do not produce to the queue until the file is uploaded
Browse files Browse the repository at this point in the history
  • Loading branch information
ayoubfaouzi committed Jul 23, 2024
1 parent 6a2faaf commit 3c9d7b7
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions internal/file/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,26 @@ func (s service) Create(ctx context.Context, req CreateFileRequest) (
time.Sleep(10 * time.Second)
}

// Check if the upload failed.
if err != nil {
s.logger.Error(err)
return
}

// Serialize the msg to send to the orchestrator.
msg, err := json.Marshal(FileScanCfg{SHA256: sha256, FileScanRequest: req.scanCfg})
if err != nil {
s.logger.Error(err)
return
}

// Push a message to the queue to scan this file.
err = s.producer.Produce(s.topic, msg)
if err != nil {
s.logger.Error(err)
return
}

}()

// Get the source of the HTTP request from the ctx.
Expand Down Expand Up @@ -272,20 +288,6 @@ func (s service) Create(ctx context.Context, req CreateFileRequest) (
return File{}, err
}

// Serialize the msg to send to the orchestrator.
msg, err := json.Marshal(FileScanCfg{SHA256: sha256, FileScanRequest: req.scanCfg})
if err != nil {
s.logger.With(ctx).Error(err)
return File{}, err
}

// Push a message to the queue to scan this file.
err = s.producer.Produce(s.topic, msg)
if err != nil {
s.logger.With(ctx).Error(err)
return File{}, err
}

return s.Get(ctx, sha256, nil)

} else {
Expand Down

0 comments on commit 3c9d7b7

Please sign in to comment.