-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ddfd86a
commit 865c69e
Showing
7 changed files
with
19 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,17 @@ | ||
package job | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/flanksource/duty/context" | ||
"gorm.io/gorm" | ||
) | ||
|
||
func RefreshConfigItemSummary3d(ctx context.Context) error { | ||
return refreshMatView(ctx, "config_item_summary_3d") | ||
return ctx.DB().Exec("REFRESH MATERIALIZED VIEW config_item_summary_3d").Error | ||
} | ||
|
||
func RefreshConfigItemSummary7d(ctx context.Context) error { | ||
return refreshMatView(ctx, "config_item_summary_7d") | ||
return ctx.DB().Exec("REFRESH MATERIALIZED VIEW config_item_summary_7d").Error | ||
} | ||
|
||
func RefreshConfigItemSummary30d(ctx context.Context) error { | ||
return refreshMatView(ctx, "config_item_summary_30d") | ||
} | ||
|
||
func refreshMatView(ctx context.Context, view string) error { | ||
return ctx.DB().Transaction(func(tx *gorm.DB) error { | ||
if err := tx.Exec("SET ROLE 'postgres'").Error; err != nil { | ||
return err | ||
} | ||
|
||
return tx.Exec(fmt.Sprintf("REFRESH MATERIALIZED VIEW %s", view)).Error | ||
}) | ||
return ctx.DB().Exec("REFRESH MATERIALIZED VIEW config_item_summary_30d").Error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters