mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2024-11-21 20:27:17 +03:00
Increase fetch interval for Codeberg
Increase the fetch interval to at least 30 seconds if the runner is configured to be used with Codeberg. This avoids it being rate limited when they do actual work and reduces load on Codeberg.
This commit is contained in:
parent
fd0596cd15
commit
db2213254d
3 changed files with 49 additions and 0 deletions
|
@ -45,6 +45,8 @@ func runDaemon(ctx context.Context, configFile *string) func(cmd *cobra.Command,
|
|||
return fmt.Errorf("failed to load registration file: %w", err)
|
||||
}
|
||||
|
||||
cfg.Tune(reg.Address)
|
||||
|
||||
lbls := reg.Labels
|
||||
if len(cfg.Runner.Labels) > 0 {
|
||||
lbls = cfg.Runner.Labels
|
||||
|
|
|
@ -68,6 +68,16 @@ type Config struct {
|
|||
Host Host `yaml:"host"` // Host represents the configuration for the host.
|
||||
}
|
||||
|
||||
// Tune the config settings accordingly to the Forgejo instance that will be used.
|
||||
func (c *Config) Tune(instanceURL string) {
|
||||
if instanceURL == "https://codeberg.org" {
|
||||
if c.Runner.FetchInterval < 30*time.Second {
|
||||
log.Info("The runner is configured to be used by a public instance, fetch interval is set to 30 seconds.")
|
||||
c.Runner.FetchInterval = 30 * time.Second
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// LoadDefault returns the default configuration.
|
||||
// If file is not empty, it will be used to load the configuration.
|
||||
func LoadDefault(file string) (*Config, error) {
|
||||
|
|
37
internal/pkg/config/config_test.go
Normal file
37
internal/pkg/config/config_test.go
Normal file
|
@ -0,0 +1,37 @@
|
|||
// Copyright 2024 The Forgejo Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package config
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestConfigTune(t *testing.T) {
|
||||
c := &Config{
|
||||
Runner: Runner{},
|
||||
}
|
||||
|
||||
t.Run("Public instance tuning", func(t *testing.T) {
|
||||
c.Runner.FetchInterval = 60 * time.Second
|
||||
c.Tune("https://codeberg.org")
|
||||
assert.EqualValues(t, 60*time.Second, c.Runner.FetchInterval)
|
||||
|
||||
c.Runner.FetchInterval = 2 * time.Second
|
||||
c.Tune("https://codeberg.org")
|
||||
assert.EqualValues(t, 30*time.Second, c.Runner.FetchInterval)
|
||||
})
|
||||
|
||||
t.Run("Non-public instance tuning", func(t *testing.T) {
|
||||
c.Runner.FetchInterval = 60 * time.Second
|
||||
c.Tune("https://example.com")
|
||||
assert.EqualValues(t, 60*time.Second, c.Runner.FetchInterval)
|
||||
|
||||
c.Runner.FetchInterval = 2 * time.Second
|
||||
c.Tune("https://codeberg.com")
|
||||
assert.EqualValues(t, 2*time.Second, c.Runner.FetchInterval)
|
||||
})
|
||||
}
|
Loading…
Reference in a new issue