Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: throttle prebuild notifications#18483

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

Closed
Show file tree
Hide file tree
Changes fromall 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
19 changes: 19 additions & 0 deletionscoderd/database/dbauthz/dbauthz.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2665,6 +2665,14 @@ func (q *querier) GetTemplateParameterInsights(ctx context.Context, arg database
return q.db.GetTemplateParameterInsights(ctx, arg)
}

func (q *querier) GetTemplatePrebuildNotificationCooldown(ctx context.Context, arg database.GetTemplatePrebuildNotificationCooldownParams) (database.TemplatePrebuildNotificationCooldown, error) {
_, err := q.GetTemplateByID(ctx, arg.TemplateID)
if err != nil {
return database.TemplatePrebuildNotificationCooldown{}, xerrors.Errorf("failed to get template by id: %w", err)
}
return q.db.GetTemplatePrebuildNotificationCooldown(ctx, arg)
}

func (q *querier) GetTemplatePresetsWithPrebuilds(ctx context.Context, templateID uuid.NullUUID) ([]database.GetTemplatePresetsWithPrebuildsRow, error) {
// GetTemplatePresetsWithPrebuilds retrieves template versions with configured presets and prebuilds.
// Presets and prebuilds are part of the template, so if you can access templates - you can access them as well.
Expand DownExpand Up@@ -5136,6 +5144,17 @@ func (q *querier) UpsertTelemetryItem(ctx context.Context, arg database.UpsertTe
return q.db.UpsertTelemetryItem(ctx, arg)
}

func (q *querier) UpsertTemplatePrebuildNotificationCooldown(ctx context.Context, arg database.UpsertTemplatePrebuildNotificationCooldownParams) error {
tmpl, err := q.db.GetTemplateByID(ctx, arg.TemplateID)
if err != nil {
return xerrors.Errorf("verify template by id: %w", err)
}
if err := q.authorizeContext(ctx, policy.ActionCreate, tmpl); err != nil {
return err
}
return q.db.UpsertTemplatePrebuildNotificationCooldown(ctx, arg)
}

func (q *querier) UpsertTemplateUsageStats(ctx context.Context) error {
if err := q.authorizeContext(ctx, policy.ActionUpdate, rbac.ResourceSystem); err != nil {
return err
Expand Down
33 changes: 33 additions & 0 deletionscoderd/database/dbauthz/dbauthz_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5087,6 +5087,39 @@ func (s *MethodTestSuite) TestPrebuilds() {
check.Args(req).
Asserts(rbac.ResourceTemplate.WithID(template.ID).InOrg(org.ID), policy.ActionUpdate)
}))
s.Run("GetTemplatePrebuildNotificationCooldown", s.Subtest(func(db database.Store, check *expects) {
org := dbgen.Organization(s.T(), db, database.Organization{})
user := dbgen.User(s.T(), db, database.User{})
template := dbgen.Template(s.T(), db, database.Template{
OrganizationID: org.ID,
CreatedBy: user.ID,
})
arg := database.GetTemplatePrebuildNotificationCooldownParams{
TemplateID: template.ID,
NotificationType: "admin",
}
check.Args(arg).
Asserts(template, policy.ActionRead).
Returns(database.TemplatePrebuildNotificationCooldown{}).
ErrorsWithPG(sql.ErrNoRows).
ErrorsWithInMemDB(dbmem.ErrUnimplemented)
}))
s.Run("UpsertTemplatePrebuildNotificationCooldown", s.Subtest(func(db database.Store, check *expects) {
org := dbgen.Organization(s.T(), db, database.Organization{})
user := dbgen.User(s.T(), db, database.User{})
template := dbgen.Template(s.T(), db, database.Template{
OrganizationID: org.ID,
CreatedBy: user.ID,
})
arg := database.UpsertTemplatePrebuildNotificationCooldownParams{
TemplateID: template.ID,
NotificationType: "admin",
}
check.Args(arg).
Asserts(template, policy.ActionCreate).
Returns().
ErrorsWithInMemDB(dbmem.ErrUnimplemented)
}))
}

func (s *MethodTestSuite) TestOAuth2ProviderApps() {
Expand Down
18 changes: 18 additions & 0 deletionscoderd/database/dbmem/dbmem.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6178,6 +6178,15 @@ func (q *FakeQuerier) GetTemplateParameterInsights(ctx context.Context, arg data
return rows, nil
}

func (q *FakeQuerier) GetTemplatePrebuildNotificationCooldown(ctx context.Context, arg database.GetTemplatePrebuildNotificationCooldownParams) (database.TemplatePrebuildNotificationCooldown, error) {
err := validateDatabaseType(arg)
if err != nil {
return database.TemplatePrebuildNotificationCooldown{}, err
}

return database.TemplatePrebuildNotificationCooldown{}, ErrUnimplemented
}

func (*FakeQuerier) GetTemplatePresetsWithPrebuilds(_ context.Context, _ uuid.NullUUID) ([]database.GetTemplatePresetsWithPrebuildsRow, error) {
return nil, ErrUnimplemented
}
Expand DownExpand Up@@ -12507,6 +12516,15 @@ func (q *FakeQuerier) UpsertTelemetryItem(_ context.Context, arg database.Upsert
return nil
}

func (q *FakeQuerier) UpsertTemplatePrebuildNotificationCooldown(ctx context.Context, arg database.UpsertTemplatePrebuildNotificationCooldownParams) error {
err := validateDatabaseType(arg)
if err != nil {
return err
}

return ErrUnimplemented
}

func (q *FakeQuerier) UpsertTemplateUsageStats(ctx context.Context) error {
q.mutex.Lock()
defer q.mutex.Unlock()
Expand Down
14 changes: 14 additions & 0 deletionscoderd/database/dbmetrics/querymetrics.go
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

29 changes: 29 additions & 0 deletionscoderd/database/dbmock/dbmock.go
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

13 changes: 13 additions & 0 deletionscoderd/database/dump.sql
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
DROP TABLE IF EXISTS template_prebuild_notification_cooldowns;
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
CREATE TABLE template_prebuild_notification_cooldowns (
template_id UUID NOT NULL,
notification_type TEXT NOT NULL,
last_notification_sent TIMESTAMPTZ NOT NULL,
PRIMARY KEY (template_id, notification_type)
);

COMMENT ON TABLE template_prebuild_notification_cooldowns IS 'Tracks when prebuild failure notifications were last sent to prevent notification noise';
COMMENT ON COLUMN template_prebuild_notification_cooldowns.notification_type IS 'Type of notification: admin or author';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
INSERT INTO
template_prebuild_notification_cooldowns (
template_id,
notification_type,
last_notification_sent
)
VALUES (
'6b298946-7a4f-47ac-9158-b03b08740a41',
'admin',
'2025-01-01 00:00:00+00'
);
8 changes: 8 additions & 0 deletionscoderd/database/models.go
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

2 changes: 2 additions & 0 deletionscoderd/database/querier.go
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

39 changes: 39 additions & 0 deletionscoderd/database/queries.sql.go
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

14 changes: 14 additions & 0 deletionscoderd/database/queries/prebuilds.sql
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -188,3 +188,17 @@ INNER JOIN organizations o ON o.id = w.organization_id
WHERE NOT t.deleted AND wpb.build_number = 1
GROUP BY t.name, tvp.name, o.name
ORDER BY t.name, tvp.name, o.name;

-- name: GetTemplatePrebuildNotificationCooldown :one
SELECT * FROM template_prebuild_notification_cooldowns
WHERE template_id = $1 AND notification_type = $2;

-- name: UpsertTemplatePrebuildNotificationCooldown :exec
INSERT INTO template_prebuild_notification_cooldowns (
template_id,
notification_type,
last_notification_sent
) VALUES (
$1, $2, $3
) ON CONFLICT (template_id, notification_type) DO UPDATE SET
last_notification_sent = $3;
1 change: 1 addition & 0 deletionscoderd/database/unique_constraint.go
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

Loading
Loading

[8]ページ先頭

©2009-2025 Movatter.jp