diff --git a/docs/content/docs/api/reference/campaigns.mdx b/docs/content/docs/api/reference/campaigns.mdx index cec3b164b..ad3e1d968 100644 --- a/docs/content/docs/api/reference/campaigns.mdx +++ b/docs/content/docs/api/reference/campaigns.mdx @@ -229,7 +229,7 @@ Create a campaign. Only `name` is required, every other field is optional and ap | `ramp_ceiling` | integer | no | Ramp ceiling, `1` to `5000` and at least `ramp_start` (default `50`). It never raises a mailbox above its own cap. | | `warmup_graduation` | boolean | no | Hold mailboxes whose warmup is running or paused to the reply-earned ceiling in this campaign: `5` a day, plus one a day for each lead who replied in the last seven days. Default `true`. `false` leaves each mailbox's daily cap, `daily_limit` and the ramp. The dashboard sets `false` with `ramp_enabled: true` for **On a schedule**, and both `false` for **Full volume**. See [ramp-up](/guides/campaigns/#ramp-up). | | `esp_match_mode` | string | no | `off`, `prefer`, or `strict`. | -| `max_new_leads_per_day` | integer | no | New-lead throttle, `0` is unlimited. | +| `max_new_leads_per_day` | integer | no | New-lead throttle, `0` is unlimited, up to `10000`. | | `prioritize_new_leads` | boolean | no | Prefer new leads in each send window. | | `entry_delay_minutes` | integer | no | Hold a contact's first email this long after they entered the campaign. `0` (the default) sends it as soon as the schedule and mailbox limits allow; the maximum is `129600` (90 days). Follow-up spacing is unaffected: that is each step's `wait_after`. | | `continuous` | boolean | no | Keep running for new leads: out of leads, the campaign stays `active` and waits instead of finishing. Linking a segment, a form or an automation that enrols leads turns it on, and so does starting a campaign whose every lead has finished. Default `false`. | diff --git a/docs/content/docs/guides/campaigns.mdx b/docs/content/docs/guides/campaigns.mdx index db7a8bd62..e2c18725f 100644 --- a/docs/content/docs/guides/campaigns.mdx +++ b/docs/content/docs/guides/campaigns.mdx @@ -340,7 +340,7 @@ Every option applies as another minimum against the mailbox's own daily cap, the Changing the option on an active campaign takes effect from its next send. Setting the schedule's numbers again keeps the level it has reached; it never goes back below the start. -**Lead flow** throttles new contacts with **Max new leads per day** (`0` for unlimited, up to `1000`). At the cap, follow-ups to in-flight contacts continue and new leads resume tomorrow. You can prioritize new leads over follow-ups, and choose whether to attempt addresses verification flagged risky. +**Lead flow** throttles new contacts with **Max new leads per day** (`0` for unlimited, up to `10000`). At the cap, follow-ups to in-flight contacts continue and new leads resume tomorrow. You can prioritize new leads over follow-ups, and choose whether to attempt addresses verification flagged risky. **Keep running for new leads** turns a campaign into an ongoing one: when it runs out of leads it stays **active** and shows **waiting for leads** instead of finishing, then sends the sequence to each lead as they arrive from a linked segment, a form, the API, Zapier, Make, n8n or an automation. Linking a segment, pointing a form at the campaign, or saving an automation that enrols leads in it turns it on, and so does pressing play on a finished campaign whose every lead is done; turn it off in the campaign's preferences to have the campaign finish once every lead is done. A campaign with this on can be started with no leads yet. An end date still ends it. diff --git a/internal/app/instanceconfig/limits.go b/internal/app/instanceconfig/limits.go index bd1a6c3c7..e3c4d3e40 100644 --- a/internal/app/instanceconfig/limits.go +++ b/internal/app/instanceconfig/limits.go @@ -38,7 +38,7 @@ func Limits() []LimitGroup { {"Campaign ramp increment", n(config.CampaignRampIncrementDefault), "emails/day", "Added each day, applied only as a lower bound against the mailbox cap."}, {"Campaign ramp ceiling", n(config.CampaignRampCeilingDefault), "emails/day", "Where the ramp stops lifting."}, {"Sender weight ceiling", n(config.CampaignSenderWeightMax), "weight", "The largest share one mailbox can take in a rotation."}, - {"New leads per campaign", n(config.CampaignMaxNewLeadsMax), "contacts", "The most contacts one campaign can pull in per run."}, + {"New leads per campaign", n(config.CampaignMaxNewLeadsMax), "contacts/day", "The highest Max new leads per day a campaign accepts."}, }, }, { diff --git a/internal/app/toolmigrate/apply.go b/internal/app/toolmigrate/apply.go index 687052682..30e064cdc 100644 --- a/internal/app/toolmigrate/apply.go +++ b/internal/app/toolmigrate/apply.go @@ -19,6 +19,7 @@ import ( "github.com/warmbly/warmbly/internal/app/campaign" "github.com/warmbly/warmbly/internal/app/contact" "github.com/warmbly/warmbly/internal/app/mailboximport" + "github.com/warmbly/warmbly/internal/config" "github.com/warmbly/warmbly/internal/models" source "github.com/warmbly/warmbly/internal/pkg/outreachsource" "github.com/warmbly/warmbly/internal/pkg/tmplvars" @@ -406,7 +407,7 @@ func (r *run) buildCampaign(c source.Campaign, name string) (*models.CreateCampa data.DailyLimit = &v } if c.MaxNewLeadsPerDay > 0 { - v := c.MaxNewLeadsPerDay + v := min(c.MaxNewLeadsPerDay, config.CampaignMaxNewLeadsMax) data.MaxNewLeadsPerDay = &v } r.schedule(c.Schedule, data, plan) diff --git a/internal/config/constants.go b/internal/config/constants.go index e37a6d30d..c7a8dc4fe 100644 --- a/internal/config/constants.go +++ b/internal/config/constants.go @@ -47,7 +47,7 @@ const ( CampaignRampStartDefault = 10 CampaignRampIncrementDefault = 5 CampaignRampCeilingDefault = 50 - CampaignMaxNewLeadsMax = 1000 + CampaignMaxNewLeadsMax = 10000 MaxContactSize = 10240 // MaxEmailBodySize bounds a single stored message body. 200 KB cut real diff --git a/internal/infrastructure/db/migrations/000422_campaign_new_leads_ceiling.down.sql b/internal/infrastructure/db/migrations/000422_campaign_new_leads_ceiling.down.sql new file mode 100644 index 000000000..98b5f1c90 --- /dev/null +++ b/internal/infrastructure/db/migrations/000422_campaign_new_leads_ceiling.down.sql @@ -0,0 +1,5 @@ +-- The old ceiling refuses values above 1000, so clamp them before restoring it. +ALTER TABLE campaigns DROP CONSTRAINT IF EXISTS campaigns_max_new_leads_per_day_range; +UPDATE campaigns SET max_new_leads_per_day = 1000 WHERE max_new_leads_per_day > 1000; +ALTER TABLE campaigns ADD CONSTRAINT campaigns_max_new_leads_per_day_check + CHECK (max_new_leads_per_day >= 0 AND max_new_leads_per_day <= 1000); diff --git a/internal/infrastructure/db/migrations/000422_campaign_new_leads_ceiling.up.sql b/internal/infrastructure/db/migrations/000422_campaign_new_leads_ceiling.up.sql new file mode 100644 index 000000000..c1abb6a28 --- /dev/null +++ b/internal/infrastructure/db/migrations/000422_campaign_new_leads_ceiling.up.sql @@ -0,0 +1,17 @@ +-- Raise the max_new_leads_per_day ceiling from 1000 to 10000 (config.CampaignMaxNewLeadsMax). +-- The 000013 CHECK was unnamed, so drop it by definition rather than by its generated name. +DO $$ +DECLARE c record; +BEGIN + FOR c IN + SELECT conname FROM pg_constraint + WHERE conrelid = 'campaigns'::regclass AND contype = 'c' + AND pg_get_constraintdef(oid) LIKE '%max_new_leads_per_day%' + LOOP + EXECUTE format('ALTER TABLE campaigns DROP CONSTRAINT %I', c.conname); + END LOOP; +END $$; + +ALTER TABLE campaigns ADD CONSTRAINT campaigns_max_new_leads_per_day_range + CHECK (max_new_leads_per_day >= 0 AND max_new_leads_per_day <= 10000) NOT VALID; +ALTER TABLE campaigns VALIDATE CONSTRAINT campaigns_max_new_leads_per_day_range; diff --git a/internal/utils/validate/campaign.go b/internal/utils/validate/campaign.go index d098d8138..09167b593 100644 --- a/internal/utils/validate/campaign.go +++ b/internal/utils/validate/campaign.go @@ -148,8 +148,8 @@ func CampaignESPMatchMode(s string) *errx.Error { } func CampaignMaxNewLeads(v int) *errx.Error { - if v < 0 || v > 1000 { - return errx.New(errx.BadRequest, "max new leads per day must be between 0 and 1000") + if v < 0 || v > config.CampaignMaxNewLeadsMax { + return errx.New(errx.BadRequest, fmt.Sprintf("max new leads per day must be between 0 and %d", config.CampaignMaxNewLeadsMax)) } return nil }