Skip to content

Commit bc21723

Browse files
authored
Make Actions tasks/jobs timeouts configurable by the user (#27400)
With this PR we added the possibility to configure the Actions timeouts values for killing tasks/jobs. Particularly this enhancement is closely related to the `act_runner` configuration reported below: ``` # The timeout for a job to be finished. # Please note that the Gitea instance also has a timeout (3h by default) for the job. # So the job could be stopped by the Gitea instance if it's timeout is shorter than this. timeout: 3h ``` --- Setting the corresponding key in the INI configuration file, it is possible to let jobs run for more than 3 hours. Signed-off-by: Francesco Antognazza <[email protected]>
1 parent dfa4e58 commit bc21723

File tree

4 files changed

+21
-9
lines changed

4 files changed

+21
-9
lines changed

custom/conf/app.example.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2568,6 +2568,12 @@ LEVEL = Info
25682568
;DEFAULT_ACTIONS_URL = github
25692569
;; Default artifact retention time in days, default is 90 days
25702570
;ARTIFACT_RETENTION_DAYS = 90
2571+
;; Timeout to stop the task which have running status, but haven't been updated for a long time
2572+
;ZOMBIE_TASK_TIMEOUT = 10m
2573+
;; Timeout to stop the tasks which have running status and continuous updates, but don't end for a long time
2574+
;ENDLESS_TASK_TIMEOUT = 3h
2575+
;; Timeout to cancel the jobs which have waiting status, but haven't been picked by a runner for a long time
2576+
;ABANDONED_JOB_TIMEOUT = 24h
25712577

25722578
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
25732579
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

docs/content/administration/config-cheat-sheet.en-us.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,6 +1389,9 @@ PROXY_HOSTS = *.github.com
13891389
- `STORAGE_TYPE`: **local**: Storage type for actions logs, `local` for local disk or `minio` for s3 compatible object storage service, default is `local` or other name defined with `[storage.xxx]`
13901390
- `MINIO_BASE_PATH`: **actions_log/**: Minio base path on the bucket only available when STORAGE_TYPE is `minio`
13911391
- `ARTIFACT_RETENTION_DAYS`: **90**: Number of days to keep artifacts. Set to 0 to disable artifact retention. Default is 90 days if not set.
1392+
- `ZOMBIE_TASK_TIMEOUT`: **10m**: Timeout to stop the task which have running status, but haven't been updated for a long time
1393+
- `ENDLESS_TASK_TIMEOUT`: **3h**: Timeout to stop the tasks which have running status and continuous updates, but don't end for a long time
1394+
- `ABANDONED_JOB_TIMEOUT`: **24h**: Timeout to cancel the jobs which have waiting status, but haven't been picked by a runner for a long time
13921395

13931396
`DEFAULT_ACTIONS_URL` indicates where the Gitea Actions runners should find the actions with relative path.
13941397
For example, `uses: actions/checkout@v3` means `https://github.com/actions/checkout@v3` since the value of `DEFAULT_ACTIONS_URL` is `github`.

modules/setting/actions.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package setting
66
import (
77
"fmt"
88
"strings"
9+
"time"
910

1011
"code.gitea.io/gitea/modules/log"
1112
)
@@ -18,6 +19,9 @@ var (
1819
ArtifactRetentionDays int64 `ini:"ARTIFACT_RETENTION_DAYS"`
1920
Enabled bool
2021
DefaultActionsURL defaultActionsURL `ini:"DEFAULT_ACTIONS_URL"`
22+
ZombieTaskTimeout time.Duration `ini:"ZOMBIE_TASK_TIMEOUT"`
23+
EndlessTaskTimeout time.Duration `ini:"ENDLESS_TASK_TIMEOUT"`
24+
AbandonedJobTimeout time.Duration `ini:"ABANDONED_JOB_TIMEOUT"`
2125
}{
2226
Enabled: true,
2327
DefaultActionsURL: defaultActionsURLGitHub,
@@ -82,5 +86,9 @@ func loadActionsFrom(rootCfg ConfigProvider) error {
8286
Actions.ArtifactRetentionDays = 90
8387
}
8488

89+
Actions.ZombieTaskTimeout = sec.Key("ZOMBIE_TASK_TIMEOUT").MustDuration(10 * time.Minute)
90+
Actions.EndlessTaskTimeout = sec.Key("ENDLESS_TASK_TIMEOUT").MustDuration(3 * time.Hour)
91+
Actions.AbandonedJobTimeout = sec.Key("ABANDONED_JOB_TIMEOUT").MustDuration(24 * time.Hour)
92+
8593
return err
8694
}

services/actions/clear_tasks.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,23 @@ import (
1212
"code.gitea.io/gitea/models/db"
1313
"code.gitea.io/gitea/modules/actions"
1414
"code.gitea.io/gitea/modules/log"
15+
"code.gitea.io/gitea/modules/setting"
1516
"code.gitea.io/gitea/modules/timeutil"
1617
)
1718

18-
const (
19-
zombieTaskTimeout = 10 * time.Minute
20-
endlessTaskTimeout = 3 * time.Hour
21-
abandonedJobTimeout = 24 * time.Hour
22-
)
23-
2419
// StopZombieTasks stops the task which have running status, but haven't been updated for a long time
2520
func StopZombieTasks(ctx context.Context) error {
2621
return stopTasks(ctx, actions_model.FindTaskOptions{
2722
Status: actions_model.StatusRunning,
28-
UpdatedBefore: timeutil.TimeStamp(time.Now().Add(-zombieTaskTimeout).Unix()),
23+
UpdatedBefore: timeutil.TimeStamp(time.Now().Add(-setting.Actions.ZombieTaskTimeout).Unix()),
2924
})
3025
}
3126

3227
// StopEndlessTasks stops the tasks which have running status and continuous updates, but don't end for a long time
3328
func StopEndlessTasks(ctx context.Context) error {
3429
return stopTasks(ctx, actions_model.FindTaskOptions{
3530
Status: actions_model.StatusRunning,
36-
StartedBefore: timeutil.TimeStamp(time.Now().Add(-endlessTaskTimeout).Unix()),
31+
StartedBefore: timeutil.TimeStamp(time.Now().Add(-setting.Actions.EndlessTaskTimeout).Unix()),
3732
})
3833
}
3934

@@ -81,7 +76,7 @@ func stopTasks(ctx context.Context, opts actions_model.FindTaskOptions) error {
8176
func CancelAbandonedJobs(ctx context.Context) error {
8277
jobs, _, err := actions_model.FindRunJobs(ctx, actions_model.FindRunJobOptions{
8378
Statuses: []actions_model.Status{actions_model.StatusWaiting, actions_model.StatusBlocked},
84-
UpdatedBefore: timeutil.TimeStamp(time.Now().Add(-abandonedJobTimeout).Unix()),
79+
UpdatedBefore: timeutil.TimeStamp(time.Now().Add(-setting.Actions.AbandonedJobTimeout).Unix()),
8580
})
8681
if err != nil {
8782
log.Warn("find abandoned tasks: %v", err)

0 commit comments

Comments
 (0)