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

Support executing registered functions registered in plugins regularly #2095

Closed
wants to merge 1 commit into from
Closed
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
16 changes: 16 additions & 0 deletions pkg/scheduler/util/scheduler_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"math/rand"
"sort"
"sync"
"time"

"k8s.io/client-go/util/workqueue"
"k8s.io/klog"
Expand All @@ -39,8 +40,23 @@ var lastProcessedNodeIndex int
// Reservation is used to record target job and locked nodes
var Reservation *ResourceReservation

// FnsLastExecTime records the last execution time of functions registering in the plugins and executing periodically
var FnsLastExecTime map[string]time.Time

func init() {
Reservation = NewResourceReservation()
FnsLastExecTime = make(map[string]time.Time)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How to register an exectTimeFn?

}

// IsToBeExecuted checks whether it is time for the function to be executed now
func IsToBeExecuted(fnName string, interval time.Duration) bool {
now := time.Now()
lastExecuteTime, ok := FnsLastExecTime[fnName]
if !ok || lastExecuteTime.Add(interval).Before(now) {
FnsLastExecTime[fnName] = now
return true
}
return false
}

// CalculateNumOfFeasibleNodesToFind returns the number of feasible nodes that once found,
Expand Down