- Notifications
You must be signed in to change notification settings - Fork1k
feat: purge old provisioner daemons#10949
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
e320d5b
6bf64d3
f44b62b
e83da41
29a8ead
f4b83ad
5a74cf9
13b7a99
142f2e2
fe84029
c489c4a
a31dbe9
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -9,12 +9,13 @@ import ( | ||
"golang.org/x/sync/errgroup" | ||
"cdr.dev/slog" | ||
"github.com/coder/coder/v2/coderd/database" | ||
"github.com/coder/coder/v2/coderd/database/dbauthz" | ||
) | ||
const ( | ||
delay =10 * time.Minute | ||
) | ||
// New creates a new periodically purging database instance. | ||
@@ -23,37 +24,47 @@ const ( | ||
// This is for cleaning up old, unused resources from the database that take up space. | ||
func New(ctx context.Context, logger slog.Logger, db database.Store) io.Closer { | ||
closed := make(chan struct{}) | ||
ctx, cancelFunc := context.WithCancel(ctx) | ||
//nolint:gocritic // The system purges old db records without user input. | ||
ctx = dbauthz.AsSystemRestricted(ctx) | ||
// Use time.Nanosecond to force an initial tick. It will be reset to the | ||
// correct duration after executing once. | ||
ticker := time.NewTicker(time.Nanosecond) | ||
doTick := func() { | ||
defer ticker.Reset(delay) | ||
mtojek marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
var eg errgroup.Group | ||
eg.Go(func() error { | ||
return db.DeleteOldWorkspaceAgentLogs(ctx) | ||
}) | ||
eg.Go(func() error { | ||
return db.DeleteOldWorkspaceAgentStats(ctx) | ||
}) | ||
eg.Go(func() error { | ||
return db.DeleteOldProvisionerDaemons(ctx) | ||
}) | ||
err := eg.Wait() | ||
if err != nil { | ||
if errors.Is(err, context.Canceled) { | ||
return | ||
} | ||
logger.Error(ctx, "failed to purge old database entries", slog.Error(err)) | ||
} | ||
} | ||
go func() { | ||
defer close(closed) | ||
defer ticker.Stop() | ||
for { | ||
select { | ||
case <-ctx.Done(): | ||
return | ||
case <-ticker.C: | ||
ticker.Stop() | ||
doTick() | ||
} | ||
} | ||
}() | ||
return &instance{ | ||
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.