forked from nuclio/nuclio
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/mpga-development' into mpga-deve…
…lopment # Conflicts: # pkg/nexus/bulk/scheduler/bulk-scheduler.go # pkg/nexus/bulk/scheduler/bulk-scheduler_test.go # pkg/nexus/common/scheduler/base-nexus-scheduler.go # pkg/nexus/deadline/scheduler/deadline-scheduler_test.go
- Loading branch information
Showing
9 changed files
with
236 additions
and
94 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
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,59 @@ | ||
package idle | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/nuclio/nuclio/pkg/nexus/common/models/interfaces" | ||
structs "github.com/nuclio/nuclio/pkg/nexus/common/models/structs" | ||
common "github.com/nuclio/nuclio/pkg/nexus/common/scheduler" | ||
) | ||
|
||
type IdleScheduler struct { | ||
common.BaseNexusScheduler | ||
} | ||
|
||
func NewScheduler(baseNexusScheduler *common.BaseNexusScheduler) *IdleScheduler { | ||
return &IdleScheduler{ | ||
BaseNexusScheduler: *baseNexusScheduler, | ||
} | ||
} | ||
|
||
func NewDefaultScheduler(baseNexusScheduler *common.BaseNexusScheduler) *IdleScheduler { | ||
return NewScheduler(baseNexusScheduler) | ||
} | ||
|
||
func (ds *IdleScheduler) Start() { | ||
ds.RunFlag = true | ||
|
||
ds.executeSchedule() | ||
} | ||
|
||
func (ds *IdleScheduler) Stop() { | ||
ds.RunFlag = false | ||
} | ||
|
||
func (ds *IdleScheduler) GetStatus() interfaces.SchedulerStatus { | ||
if ds.RunFlag { | ||
return interfaces.Running | ||
} else { | ||
return interfaces.Stopped | ||
} | ||
} | ||
|
||
func (ds *IdleScheduler) executeSchedule() { | ||
for ds.RunFlag { | ||
nextWakeUpTime := time.Now().Add(ds.SleepDuration) | ||
|
||
for ds.Queue.Len() > 0 && ds.MaxParallelRequests.Load() > 0 { | ||
ds.MaxParallelRequests.Add(-1) | ||
task := ds.Queue.Pop() | ||
go func(taskInFunction *structs.NexusItem) { | ||
defer ds.MaxParallelRequests.Add(1) | ||
ds.CallSynchronized(taskInFunction) | ||
}(task) | ||
} | ||
|
||
// sleep until the next wake up time | ||
time.Sleep(time.Until(nextWakeUpTime)) | ||
} | ||
} |
Oops, something went wrong.