guardsync

package
v0.110.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2026 License: AGPL-3.0 Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const JobSync = "guard_lists.sync"

JobSync syncs one guard connection's list.

Variables

View Source
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.

View Source
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 Source

func Source(connector string) string

Source is the opt-out list's source for a connector's list entries.

func SuppressionReason

func SuppressionReason(guardReason string) string

SuppressionReason is the opt-out list reason for what a guard's list means: customer, or blocklist.

Types

type Result

type Result struct {
	Added, Removed int
	// More is a feed that stopped before its end.
	More bool
}

Result is what one sync did.

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) Loop

func (s *Service) Loop(ctx context.Context, interval time.Duration)

Loop queues a sync for every guard connection that is due.

func (*Service) QueueDue

func (s *Service) QueueDue(ctx context.Context) error

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.

func (*Service) Register

func (s *Service) Register(q *jobs.Queue)

Register handles the sync job, and syncs a guard straight away when it is connected.

func (*Service) Sync

func (s *Service) Sync(ctx context.Context, ws, integrationID string) (Result, error)

Sync reads one guard connection's list into the opt-out list.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL