fix: add missing method RunWithResource

This commit is contained in:
wanglei.w
2022-01-29 14:51:36 +08:00
parent 78eb37f868
commit 3cc1710421
2 changed files with 5 additions and 1 deletions

View File

@@ -26,7 +26,7 @@ func ComplexFilterExample(testInputFile, testOverlayFile, testOutputFile string)
// 1386105 root 20 0 2114152 273780 31672 R 50.2 1.7 0:16.79 ffmpeg
func TestLimitCpu(t *testing.T) {
e := ComplexFilterExample("./sample_data/in1.mp4", "./sample_data/overlay.png", "./sample_data/out2.mp4")
err := e.WithCpuCoreRequest(0.1).WithCpuCoreLimit(0.5).RunLinux()
err := e.RunWithResource(0.1, 0.5)
if err != nil {
assert.Nil(t, err)
}

View File

@@ -68,6 +68,10 @@ func writeCGroupFile(rootPath, file string, value string) error {
return ioutil.WriteFile(filepath.Join(rootPath, file), []byte(value), 0755)
}
func (s *Stream) RunWithResource(cpuRequest, cpuLimit float32) error {
return s.WithCpuCoreRequest(cpuRequest).WithCpuCoreLimit(cpuLimit).RunLinux()
}
func (s *Stream) RunLinux() error {
a := s.Context.Value(cgroupConfigKey).(*cgroupConfig)
if a.cpuRequest > a.cpuLimit {