Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions acceleration/cmd/router/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ const (
// runs first, and the HTTP drain gets the rest of shutdownGrace, so both fit inside the
// orchestrator's termination grace period.
phoneHangupGrace = 5 * time.Second
// legFlushTimeout bounds the last write of the call legs the leg sweep still holds, once
// the HTTP and session drains are over: one insert a leg, of at most a few, normally.
legFlushTimeout = 5 * time.Second
// usageDrainTimeout is how long the usage writer has to write what is queued once
// everything that records has stopped: it starts after the HTTP drain, any session drain
// and sessions.Shutdown, and counts none of them. What is still queued after it is lost,
Expand Down Expand Up @@ -1196,6 +1199,13 @@ func run(settings config.Config, logger *slog.Logger) error {
// leg whose row was lost is recorded again. Months of numbers and of 10DLC campaigns are
// billed by jobs of their own (router usage numbers, router usage dlc).
go telephony.RunLegSweep(ctx, legSweepEvery)
// Deferred here, it runs after the drain and sessions.Shutdown, so the legs a webhook or
// a session still kept get their last write, and before the usage writer closes.
defer func() {
ctx, cancel := context.WithTimeout(context.Background(), legFlushTimeout)
defer cancel()
telephony.StopLegSweep(ctx)
}()
go checkCallHook(ctx, settings, logger)
startPhoneSweeper(ctx, telephony, logger)
}
Expand Down
10 changes: 8 additions & 2 deletions acceleration/cmd/router/phonesweep.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ var phoneSweepEvery = 10 * time.Minute
const phoneCallMaxAge = 6 * time.Hour

// startPhoneSweeper deletes the per-call trunks of calls that never reported their end and the
// bridges of calls nobody answered, and retires the status urls of old placed calls, until ctx
// is done.
// bridges of calls nobody answered, settles the purchases and releases of numbers whose outcome
// was not recorded, and retires the status urls of old placed calls, until ctx is done.
func startPhoneSweeper(ctx context.Context, service *phone.Service, logger *slog.Logger) {
// Read before the goroutine, so a test that sets it back after run returns does not race it.
every := phoneSweepEvery
Expand All @@ -41,6 +41,12 @@ func startPhoneSweeper(ctx context.Context, service *phone.Service, logger *slog
} else if bridges > 0 {
logger.Info("swept the bridges of calls nobody answered", "bridges", bridges)
}
orders, err := service.SweepOrders(ctx)
if err != nil {
logger.Error("could not settle the purchases and releases of numbers left unrecorded", "error", err)
} else if orders > 0 {
logger.Info("settled the purchases and releases of numbers left unrecorded", "orders", orders)
}
retired, err := service.SweepStatusTokens(ctx)
if err != nil {
logger.Error("could not retire the status urls of old placed calls", "error", err)
Expand Down
Loading
Loading