Skip to content

Commit

Permalink
Merge pull request #670 from sapcc/fix_projectID
Browse files Browse the repository at this point in the history
[campfire] chose the project uuid for the query body
  • Loading branch information
majewsky authored Feb 27, 2025
2 parents 384eb87 + 0231281 commit ba075fc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
17 changes: 11 additions & 6 deletions internal/collector/mail_delivery.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ import (
)

type MailRequest struct {
ProjectID db.ProjectID `json:"project_id"`
Subject string `json:"subject"`
MimeType string `json:"mime_type"`
MailText string `json:"mail_text"`
ProjectID string `json:"project_id"`
Subject string `json:"subject"`
MimeType string `json:"mime_type"`
MailText string `json:"mail_text"`
}

const (
Expand Down Expand Up @@ -78,8 +78,13 @@ func (c *Collector) discoverMailDeliveryTask(_ context.Context, _ prometheus.Lab
}

func (c *Collector) processMailDeliveryTask(ctx context.Context, task db.MailNotification, client MailClient, _ prometheus.Labels) error {
var projectUUID string
err := c.DB.SelectOne(&projectUUID, "SELECT uuid FROM projects WHERE id = $1", task.ProjectID)
if err != nil {
return err
}
request := MailRequest{
ProjectID: task.ProjectID,
ProjectID: projectUUID,
Subject: task.Subject,
MimeType: "text/html",
MailText: task.Body,
Expand All @@ -95,7 +100,7 @@ func (c *Collector) processMailDeliveryTask(ctx context.Context, task db.MailNot
}
return mailErr
}
_, err := c.DB.Delete(&task)
_, err = c.DB.Delete(&task)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions internal/collector/mail_delivery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ type MockMail struct{}

func (m *MockMail) PostMail(ctx context.Context, req MailRequest) error {
switch req.ProjectID {
case 1:
case "uuid-for-waldorf":
return nil
case 2:
case "uuid-for-berlin":
return errors.New("fail project id 1")
case 3:
case "uuid-for-dresden":
return nil
}
return nil
Expand Down

0 comments on commit ba075fc

Please sign in to comment.