Documentation
¶
Overview ¶
Package guardsync keeps a copy of each contact guard's whole list (a product's account feed, a shared blocklist's exports) in the workspace's opt-out list, so a company is checked against the copy without a call, and whoever joins the list is stopped like anyone else on it: a sequence Outflare sends checks the opt-out list before every email, and the suppression syncs write it to connected sequencers' blocklists.
Each guard connection whose connector can read its list (connectors.GuardLister) is synced by a job on its own schedule. A feed is read from where the last sync stopped, so only what is new is read; its first sync reads it all, in bounded runs that pick up from their cursor. A snapshot is read whole each time and compared with the copy: what left it is removed, and only entries this sync added are ever removed. Entries carry the source <connector>_sync, the reason the guard's list means (customer, or blocklist) and the connection's id.
The live checks are unchanged: before anyone is added to a campaign, the guard itself is asked, since the copy is only as new as its last sync.
Index ¶
- Constants
- Variables
- func CompanyListed(ctx context.Context, q jobs.Querier, ...) (listed, ok bool, err error)
- func Fresh(ctx context.Context, q jobs.Querier, reg *connectors.Registry, ...) (bool, error)
- func Info(reg *connectors.Registry, connector string) (connectors.GuardListInfo, bool)
- func Interval(info connectors.GuardListInfo, seconds *int) time.Duration
- func Listers(reg *connectors.Registry) []string
- func Request(ctx context.Context, q jobs.Querier, ws, integrationID string, ...) error
- func Source(connector string) string
- func SuppressionReason(guardReason string) string
- type Result
- type Service
Constants ¶
const JobSync = "guard_lists.sync"
JobSync syncs one guard connection's list.
Variables ¶
var ( // RunBudget is how long one sync of a feed reads before it stops and // queues the next, and FeedPages the most pages it reads. RunBudget = 4 * time.Minute FeedPages = 400 // Lease is how long a sync holds its connection's row: a second sync // waits for it, or for it to run out if the process died. Lease = 15 * time.Minute // RetryMin is the least a failed sync waits before the next try. RetryMin = time.Minute // FreshFactor: a copy is used in place of the guard while its last // success is within this many intervals. FreshFactor = 2 )
Limits of one sync, as variables so tests can change them.
var ( // ErrNotLister is a connection whose connector can't read its list. ErrNotLister = errors.New("this connection's list cannot be read") // ErrBusy is a sync already running for the connection. ErrBusy = errors.New("a sync of this list is already running") // ErrOff is a list sync turned off. ErrOff = errors.New("this list sync is turned off") )
Functions ¶
func CompanyListed ¶
func CompanyListed(ctx context.Context, q jobs.Querier, ws, integrationID, connector, domain string) (listed, ok bool, err error)
CompanyListed says whether a company's domain, or a domain it is under, is on a guard connection's copy. ok is false for a domain that can't be read or is a mailbox provider's: the copy says nothing about those.
func Fresh ¶
func Fresh(ctx context.Context, q jobs.Querier, reg *connectors.Registry, ws, integrationID, connector string, now time.Time) (bool, error)
Fresh says whether the copy of a guard connection's list can be used in place of asking the guard: its sync is on, has read the whole list once, and last succeeded within FreshFactor of its intervals.
func Info ¶
func Info(reg *connectors.Registry, connector string) (connectors.GuardListInfo, bool)
Info is how a connector's list is read, and ok whether it can be.
func Interval ¶
func Interval(info connectors.GuardListInfo, seconds *int) time.Duration
Interval is how often a list is read: the connection's own setting, or the connector's default.
func Listers ¶
func Listers(reg *connectors.Registry) []string
Listers are the ids of the connectors that can read their guard list.
func Request ¶
func Request(ctx context.Context, q jobs.Querier, ws, integrationID string, delay time.Duration) error
Request queues a sync of one guard connection after delay. Requests in the same minute share one run.
func SuppressionReason ¶
SuppressionReason is the opt-out list reason for what a guard's list means: customer, or blocklist.
Types ¶
type Service ¶
type Service struct {
Pool *pgxpool.Pool
Store *connectors.Store
Log *slog.Logger
// Now is overridable in tests.
Now func() time.Time
}
Service syncs guard lists.
func (*Service) QueueDue ¶
QueueDue queues a sync for every enabled guard connection whose last try is older than its interval and that is not waiting after a failure.