1
0
mirror of https://github.com/rancher/norman.git synced 2025-08-31 14:51:57 +00:00

Add EnqueueAfter

This commit is contained in:
Darren Shepherd
2020-02-05 21:15:26 -07:00
parent 34d59ccb8e
commit 202dd06a36
2 changed files with 13 additions and 0 deletions

View File

@@ -50,6 +50,7 @@ type GenericController interface {
AddHandler(ctx context.Context, name string, handler HandlerFunc)
HandlerCount() int
Enqueue(namespace, name string)
EnqueueAfter(namespace, name string, after time.Duration)
Sync(ctx context.Context) error
Start(ctx context.Context, threadiness int) error
}
@@ -122,6 +123,16 @@ func (g *genericController) Enqueue(namespace, name string) {
}
}
func (g *genericController) EnqueueAfter(namespace, name string, after time.Duration) {
key := name
if namespace != "" {
key = namespace + "/" + name
}
if g.queue != nil {
g.queue.AddAfter(key, after)
}
}
func (g *genericController) AddHandler(ctx context.Context, name string, handler HandlerFunc) {
t := getHandlerTransaction(ctx)
if t == nil {

View File

@@ -4,6 +4,7 @@ var controllerTemplate = `package {{.schema.Version.Version}}
import (
"context"
"time"
{{.importPackage}}
"github.com/rancher/norman/objectclient"
@@ -78,6 +79,7 @@ type {{.schema.CodeName}}Controller interface {
AddClusterScopedHandler(ctx context.Context, name, clusterName string, handler {{.schema.CodeName}}HandlerFunc)
AddClusterScopedFeatureHandler(ctx context.Context, enabled func() bool, name, clusterName string, handler {{.schema.CodeName}}HandlerFunc)
Enqueue(namespace, name string)
EnqueueAfter(namespace, name string, after time.Duration)
Sync(ctx context.Context) error
Start(ctx context.Context, threadiness int) error
}