-
Notifications
You must be signed in to change notification settings - Fork 208
Allow configuring trigger frequency when application is out_of_sync #2793
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,9 +18,11 @@ import ( | |
| "context" | ||
| "fmt" | ||
| "strings" | ||
| "time" | ||
|
|
||
| "go.uber.org/zap" | ||
|
|
||
| "github.com/pipe-cd/pipe/pkg/app/api/service/pipedservice" | ||
| "github.com/pipe-cd/pipe/pkg/config" | ||
| "github.com/pipe-cd/pipe/pkg/filematcher" | ||
| "github.com/pipe-cd/pipe/pkg/git" | ||
|
|
@@ -51,6 +53,10 @@ func (ds *determiners) Determiner(ck candidateKind) Determiner { | |
| type OnCommandDeterminer struct { | ||
| } | ||
|
|
||
| func NewOnCommandDeterminer() *OnCommandDeterminer { | ||
| return &OnCommandDeterminer{} | ||
| } | ||
|
|
||
| // ShouldTrigger decides whether a given application should be triggered or not. | ||
| func (d *OnCommandDeterminer) ShouldTrigger(_ context.Context, _ *model.Application, appCfg *config.GenericDeploymentSpec) (bool, error) { | ||
| if appCfg.Trigger.OnCommand.Disabled { | ||
|
|
@@ -61,14 +67,49 @@ func (d *OnCommandDeterminer) ShouldTrigger(_ context.Context, _ *model.Applicat | |
| } | ||
|
|
||
| type OnOutOfSyncDeterminer struct { | ||
| client apiClient | ||
| } | ||
|
|
||
| func NewOnOutOfSyncDeterminer(client apiClient) *OnOutOfSyncDeterminer { | ||
| return &OnOutOfSyncDeterminer{ | ||
| client: client, | ||
| } | ||
| } | ||
|
|
||
| // ShouldTrigger decides whether a given application should be triggered or not. | ||
| func (d *OnOutOfSyncDeterminer) ShouldTrigger(_ context.Context, _ *model.Application, appCfg *config.GenericDeploymentSpec) (bool, error) { | ||
| func (d *OnOutOfSyncDeterminer) ShouldTrigger(ctx context.Context, app *model.Application, appCfg *config.GenericDeploymentSpec) (bool, error) { | ||
| if *appCfg.Trigger.OnOutOfSync.Disabled { | ||
| return false, nil | ||
| } | ||
|
|
||
| // Find the most recently triggered deployment. | ||
| // Nil means it seems the application has been added recently | ||
| // and no deployment was triggered yet. | ||
| ref := app.MostRecentlyTriggeredDeployment | ||
| if ref == nil { | ||
| return true, nil | ||
| } | ||
|
|
||
| resp, err := d.client.GetDeployment(ctx, &pipedservice.GetDeploymentRequest{ | ||
| Id: ref.DeploymentId, | ||
| }) | ||
| if err != nil { | ||
| return false, err | ||
| } | ||
| deployment := resp.Deployment | ||
|
|
||
| // Check if it was already completed or not. | ||
| // Not yet completed means the application is deploying currently, | ||
| // so no need to trigger a new deployment for it. | ||
| if !model.IsCompletedDeployment(deployment.Status) { | ||
| return false, nil | ||
| } | ||
|
|
||
| // Check the elapsed time since the last deployment. | ||
| if time.Since(time.Unix(deployment.CompletedAt, 0)) < appCfg.Trigger.OnOutOfSync.MinWindow.Duration() { | ||
| return false, nil | ||
| } | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tbh, it looks like this determiner will trigger a new deployment whenever
Those two are good to me, but since this determiner is for the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This is correct.
We don't need that logic because this determiner is accepting only OUT_OF_SYNC candidates. |
||
| return true, nil | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.