Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

store PR runs per commit ID #224

Merged
merged 1 commit into from
Jun 19, 2024
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
2 changes: 1 addition & 1 deletion runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ func (r *Runner) updateRedis(ctx context.Context, run *tfaplv1beta1.Run) error {

// if its PR run only update relevant PR key
if run.Request.Type == tfaplv1beta1.PRPlan {
return r.Redis.SetPRLastRun(ctx, run)
return r.Redis.SetPRRun(ctx, run)
}

// set default last run
Expand Down
18 changes: 9 additions & 9 deletions sysutil/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ var (
type RedisInterface interface {
DefaultLastRun(ctx context.Context, module types.NamespacedName) (*tfaplv1beta1.Run, error)
DefaultApply(ctx context.Context, module types.NamespacedName) (*tfaplv1beta1.Run, error)
PRLastRun(ctx context.Context, module types.NamespacedName, pr int) (*tfaplv1beta1.Run, error)
PRRun(ctx context.Context, module types.NamespacedName, pr int, hash string) (*tfaplv1beta1.Run, error)
Runs(ctx context.Context, module types.NamespacedName) ([]*tfaplv1beta1.Run, error)
GetCommitHash(ctx context.Context, key string) (string, error)

SetDefaultLastRun(ctx context.Context, run *tfaplv1beta1.Run) error
SetDefaultApply(ctx context.Context, run *tfaplv1beta1.Run) error
SetPRLastRun(ctx context.Context, run *tfaplv1beta1.Run) error
SetPRRun(ctx context.Context, run *tfaplv1beta1.Run) error
}

type Redis struct {
Expand All @@ -46,8 +46,8 @@ func defaultLastApplyKey(module types.NamespacedName) string {
return fmt.Sprintf("%sdefault:lastApply", keyPrefix(module))
}

func DefaultPRLastRunsKey(module types.NamespacedName, pr int) string {
return fmt.Sprintf("%sPR:%d:lastRun", keyPrefix(module), pr)
func DefaultPRLastRunsKey(module types.NamespacedName, pr int, hash string) string {
return fmt.Sprintf("%sPR:%d:%s", keyPrefix(module), pr, hash)
}

// DefaultLastRun will return last run result for the default branch
Expand All @@ -61,8 +61,8 @@ func (r Redis) DefaultApply(ctx context.Context, module types.NamespacedName) (*
}

// PRLastRun will return last run result for the given PR branch
func (r Redis) PRLastRun(ctx context.Context, module types.NamespacedName, pr int) (*tfaplv1beta1.Run, error) {
return r.getKV(ctx, DefaultPRLastRunsKey(module, pr))
func (r Redis) PRRun(ctx context.Context, module types.NamespacedName, pr int, hash string) (*tfaplv1beta1.Run, error) {
return r.getKV(ctx, DefaultPRLastRunsKey(module, pr, hash))
}

// Runs will return all the runs stored for the given module
Expand Down Expand Up @@ -94,9 +94,9 @@ func (r Redis) SetDefaultApply(ctx context.Context, run *tfaplv1beta1.Run) error
return r.setKV(ctx, defaultLastApplyKey(run.Module), run, 0)
}

// SetPRLastRun puts given run in to cache with expiration
func (r Redis) SetPRLastRun(ctx context.Context, run *tfaplv1beta1.Run) error {
return r.setKV(ctx, DefaultPRLastRunsKey(run.Module, run.Request.PR.Number), run, PRKeyExpirationDur)
// SetPRRun puts given run in to cache with expiration
func (r Redis) SetPRRun(ctx context.Context, run *tfaplv1beta1.Run) error {
return r.setKV(ctx, DefaultPRLastRunsKey(run.Module, run.Request.PR.Number, run.CommitHash), run, PRKeyExpirationDur)
}

func (r Redis) setKV(ctx context.Context, key string, run *tfaplv1beta1.Run, exp time.Duration) error {
Expand Down
39 changes: 27 additions & 12 deletions sysutil/redis_mock.go

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

Loading