Skip to content

Commit

Permalink
Merge branch 'fix-campaign-sent'
Browse files Browse the repository at this point in the history
  • Loading branch information
knadh committed Jan 4, 2024
2 parents 9a96134 + 772476c commit 8add9d6
Show file tree
Hide file tree
Showing 7 changed files with 520 additions and 385 deletions.
4 changes: 4 additions & 0 deletions cmd/campaigns.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ func handleUpdateCampaignStatus(c echo.Context) error {
return err
}

if o.Status == models.CampaignStatusPaused || o.Status == models.CampaignStatusCancelled {
app.manager.StopCampaign(id)
}

return c.JSON(http.StatusOK, okResp{out})
}

Expand Down
2 changes: 0 additions & 2 deletions cmd/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ func handleEventStream(c echo.Context) error {
continue
}

fmt.Printf("data: %s\n\n", b)

c.Response().Write([]byte(fmt.Sprintf("retry: 3000\ndata: %s\n\n", b)))
c.Response().Flush()

Expand Down
14 changes: 11 additions & 3 deletions cmd/manager_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ func newManagerStore(q *models.Queries, c *core.Core, m media.Store) *store {
}
}

// NextCampaigns retrieves active campaigns ready to be processed.
func (s *store) NextCampaigns(excludeIDs []int64) ([]*models.Campaign, error) {
// NextCampaigns retrieves active campaigns ready to be processed excluding
// campaigns that are also being processed. Additionally, it takes a map of campaignID:sentCount
// of campaigns that are being processed and updates them in the DB.
func (s *store) NextCampaigns(currentIDs []int64, sentCounts []int64) ([]*models.Campaign, error) {
var out []*models.Campaign
err := s.queries.NextCampaigns.Select(&out, pq.Int64Array(excludeIDs))
err := s.queries.NextCampaigns.Select(&out, pq.Int64Array(currentIDs), pq.Int64Array(sentCounts))
return out, err
}

Expand All @@ -58,6 +60,12 @@ func (s *store) UpdateCampaignStatus(campID int, status string) error {
return err
}

// UpdateCampaignStatus updates a campaign's status.
func (s *store) UpdateCampaignCounts(campID int, toSend int, sent int, lastSubID int) error {
_, err := s.queries.UpdateCampaignCounts.Exec(campID, toSend, sent, lastSubID)
return err
}

// GetAttachment fetches a media attachment blob.
func (s *store) GetAttachment(mediaID int) (models.Attachment, error) {
m, err := s.core.GetMedia(mediaID, "", s.media)
Expand Down
Loading

0 comments on commit 8add9d6

Please sign in to comment.