-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: workflow template support record last run time with workqueue. F…
…ixes #1915 Signed-off-by: qingfeng777 <[email protected]>
- Loading branch information
1 parent
071f92b
commit 5bc7bdc
Showing
4 changed files
with
174 additions
and
13 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package templateresolution | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/argoproj/pkg/sync" | ||
log "github.com/sirupsen/logrus" | ||
runtimeutil "k8s.io/apimachinery/pkg/util/runtime" | ||
"k8s.io/client-go/util/workqueue" | ||
) | ||
|
||
type wftmplStatusQueue struct { | ||
wftmplQueue workqueue.RateLimitingInterface | ||
cwftmplQueue workqueue.RateLimitingInterface | ||
|
||
keyLock sync.KeyLock | ||
ckeyLock sync.KeyLock | ||
ctx *Context | ||
} | ||
|
||
func NewTmplStatusQueue(ctx *Context) *wftmplStatusQueue { | ||
return &wftmplStatusQueue{ | ||
wftmplQueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "tmpl-status-queue"), | ||
cwftmplQueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "ctmpl-status-queue"), | ||
keyLock: sync.NewKeyLock(), | ||
ckeyLock: sync.NewKeyLock(), | ||
ctx: ctx, | ||
} | ||
} | ||
|
||
func (q *wftmplStatusQueue) run(ctx context.Context) { | ||
defer q.wftmplQueue.ShutDown() | ||
defer q.cwftmplQueue.ShutDown() | ||
go q.runTmplStatusUpdate() | ||
go q.runCtmplStatusUpdate() | ||
<-ctx.Done() | ||
} | ||
|
||
func (q *wftmplStatusQueue) runTmplStatusUpdate() { | ||
ctx := context.TODO() | ||
for q.processNextTmplItem(ctx) { | ||
} | ||
} | ||
|
||
func (q *wftmplStatusQueue) runCtmplStatusUpdate() { | ||
ctx := context.TODO() | ||
for q.processNextCtmplItem(ctx) { | ||
} | ||
} | ||
|
||
func (q *wftmplStatusQueue) processNextTmplItem(ctx context.Context) bool { | ||
defer runtimeutil.HandleCrash(runtimeutil.PanicHandlers...) | ||
|
||
key, quit := q.wftmplQueue.Get() | ||
if quit { | ||
return false | ||
} | ||
defer q.wftmplQueue.Done(key) | ||
|
||
q.keyLock.Lock(key.(string)) | ||
defer q.keyLock.Unlock(key.(string)) | ||
|
||
logCtx := log.WithField("wftmplStatus", key) | ||
logCtx.Infof("Processing %s", key) | ||
|
||
err := q.ctx.updateTemplateStatus(key.(string)) | ||
if err != nil { | ||
log.Errorf("Update workflow template %s err: %v", key.(string), err) | ||
} | ||
return true | ||
} | ||
|
||
func (q *wftmplStatusQueue) processNextCtmplItem(ctx context.Context) bool { | ||
defer runtimeutil.HandleCrash(runtimeutil.PanicHandlers...) | ||
|
||
key, quit := q.cwftmplQueue.Get() | ||
if quit { | ||
return false | ||
} | ||
defer q.cwftmplQueue.Done(key) | ||
|
||
q.ckeyLock.Lock(key.(string)) | ||
defer q.ckeyLock.Unlock(key.(string)) | ||
|
||
logCtx := log.WithField("cwftmplStatus", key) | ||
logCtx.Infof("Processing %s", key) | ||
|
||
err := q.ctx.updateCtemplateStatus(key.(string)) | ||
if err != nil { | ||
log.Errorf("Update cluster workflow template %s err: %v", key.(string), err) | ||
} | ||
return true | ||
} |