mirror of
https://github.com/semaphoreui/semaphore.git
synced 2025-01-20 15:29:28 +01:00
feat(backend): add config option max_task_duration_sec
This commit is contained in:
parent
7e7a543e03
commit
34485b7b8e
@ -7,6 +7,7 @@ import (
|
||||
"github.com/ansible-semaphore/semaphore/db"
|
||||
"github.com/ansible-semaphore/semaphore/db_lib"
|
||||
"github.com/ansible-semaphore/semaphore/lib"
|
||||
"github.com/ansible-semaphore/semaphore/util"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
@ -120,7 +121,16 @@ func (t *RemoteJob) Run(username string, incomingVersion *string) (err error) {
|
||||
|
||||
tsk.RunnerID = runner.ID
|
||||
|
||||
startTime := time.Now()
|
||||
|
||||
taskTimedOut := false
|
||||
|
||||
for {
|
||||
if util.Config.MaxTaskDurationSec > 0 && int(time.Now().Sub(startTime).Seconds()) > util.Config.MaxTaskDurationSec {
|
||||
taskTimedOut = true
|
||||
break
|
||||
}
|
||||
|
||||
time.Sleep(1_000_000_000)
|
||||
tsk = t.taskPool.GetTask(t.Task.ID)
|
||||
if tsk.Task.Status == lib.TaskSuccessStatus ||
|
||||
@ -138,6 +148,8 @@ func (t *RemoteJob) Run(username string, incomingVersion *string) (err error) {
|
||||
|
||||
if tsk.Task.Status == lib.TaskFailStatus {
|
||||
err = fmt.Errorf("task failed")
|
||||
} else if taskTimedOut {
|
||||
err = fmt.Errorf("task timed out")
|
||||
}
|
||||
|
||||
return
|
||||
|
@ -169,6 +169,8 @@ type ConfigType struct {
|
||||
// oidc settings
|
||||
OidcProviders map[string]OidcProvider `json:"oidc_providers"`
|
||||
|
||||
MaxTaskDurationSec int `json:"max_task_duration_sec" env:"MAX_TASK_DURATION_SEC"`
|
||||
|
||||
// task concurrency
|
||||
MaxParallelTasks int `json:"max_parallel_tasks" default:"10" rule:"^[0-9]{1,10}$" env:"SEMAPHORE_MAX_PARALLEL_TASKS"`
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user