Skip to content

Commit

Permalink
chore: increase the retry times (#49)
Browse files Browse the repository at this point in the history
Co-authored-by: rick <[email protected]>
  • Loading branch information
LinuxSuRen and LinuxSuRen authored Mar 11, 2024
1 parent 5e9c409 commit b7dacce
Show file tree
Hide file tree
Showing 9 changed files with 409 additions and 174 deletions.
38 changes: 32 additions & 6 deletions cmd/argoworkflow/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
/*
MIT License
Copyright (c) 2023-2024 Rick
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

package main

import (
Expand Down Expand Up @@ -178,12 +202,14 @@ func (e *DefaultPluginExecutor) Execute(args executor.ExecuteTemplateArgs, wf *w
}

fmt.Println("send status", repo)
wait.PollImmediate(time.Second, time.Second*10, func() (bool, error) {
err := pkg.CreateStatus(ctx, repo)
return err == nil, nil
})

fmt.Println("send status success")
if err = wait.PollImmediate(time.Second*2, time.Second*20, func() (bool, error) {
return pkg.CreateStatus(ctx, repo) == nil, nil
}); err == nil {
fmt.Println("send status success", repo)
} else {
fmt.Printf("failed to send the status to %v: %v\n", repo, err)
return
}

if err == nil && opt.Option.CreateComment {
fmt.Println("start to create comment")
Expand Down
2 changes: 2 additions & 0 deletions cmd/argoworkflow/template/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package template

// CommentTemplate is the default comment template
const CommentTemplate = `
<!-- Generated by https://github.com/LinuxSuRen/gogit -->
[{{.Spec.WorkflowTemplateRef.Name}}]({{get .Annotations "workflow.templatelink"}}) is {{.Status.Phase}}. It started from {{date "01-02 15:04" .Status.StartedAt.Time}}, and took {{duration .Status.FinishedAt .Status.StartedAt}}. Please check log output from [here]({{get .Annotations "workflow.link"}}).
| Stage | Status | Duration |
Expand All @@ -12,6 +13,7 @@ const CommentTemplate = `
`

const OutputsTemplate = `
<!-- Generated by https://github.com/LinuxSuRen/gogit -->
Please feel free to check the following outputs:
| Output |
Expand Down
6 changes: 5 additions & 1 deletion cmd/argoworkflow/template/comment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func TestCommentTemlate(t *testing.T) {
func TestCommentTemplate(t *testing.T) {
var layout string = "2006-01-02 15:04:05"
var timeStr string = "2019-12-12 15:22:12"
targetTime, err := time.ParseInLocation(layout, timeStr, time.Local)
Expand Down Expand Up @@ -51,6 +51,7 @@ func TestCommentTemlate(t *testing.T) {
result, err := template.RenderTemplate(template.CommentTemplate, object)
assert.Nil(t, err)
assert.Equal(t, `
<!-- Generated by https://github.com/LinuxSuRen/gogit -->
[Sample](https://github.com/linxusuren/gogit.git) is Failed. It started from 12-12 15:22, and took 5s. Please check log output from [here](https://github.com/linxusuren/gogit).
| Stage | Status | Duration |
Expand All @@ -60,6 +61,7 @@ func TestCommentTemlate(t *testing.T) {
`, result)

result, err = template.RenderTemplate(`
<!-- Generated by https://github.com/LinuxSuRen/gogit -->
| Stage | Status | Duration |
|---|---|---|
{{ range $node, $status := .Status.Nodes -}}
Expand All @@ -68,6 +70,7 @@ func TestCommentTemlate(t *testing.T) {
`, object)
assert.Nil(t, err)
assert.Equal(t, `
<!-- Generated by https://github.com/LinuxSuRen/gogit -->
| Stage | Status | Duration |
|---|---|---|
| node-1 | Success | 5m19s |
Expand All @@ -94,6 +97,7 @@ func TestOutput(t *testing.T) {
result, err := template.RenderTemplate(template.OutputsTemplate, objects)
assert.Nil(t, err)
assert.Equalf(t, `
<!-- Generated by https://github.com/LinuxSuRen/gogit -->
Please feel free to check the following outputs:
| Output |
Expand Down
8 changes: 5 additions & 3 deletions cmd/argoworkflow/template/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@ func TestDuration(t *testing.T) {
assert.Equal(t, "3s", result)
},
}, {
name: "have not finished",
startedAt: now,
name: "have not finished",
startedAt: v1.Time{
Time: now.Add(time.Millisecond * -1),
},
verify: func(t *testing.T, result string) {
assert.True(t, strings.HasSuffix(result, "µs"))
assert.True(t, strings.HasSuffix(result, "ms"), result)
},
}}
for _, tt := range tests {
Expand Down
Loading

0 comments on commit b7dacce

Please sign in to comment.