Set MAX_JOB_DURATION_SECONDS from jobservice config.yml (#22116)

Signed-off-by: stonezdj <stone.zhang@broadcom.com>
This commit is contained in:
stonezdj(Daojun Zhang) 2025-07-18 18:01:18 +08:00 committed by GitHub
parent 440f53ebbc
commit ebdfb547ba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 14 additions and 4 deletions

View File

@ -23,7 +23,6 @@ HTTPS_PROXY={{jobservice_https_proxy}}
NO_PROXY={{jobservice_no_proxy}}
REGISTRY_CREDENTIAL_USERNAME={{registry_username}}
REGISTRY_CREDENTIAL_PASSWORD={{registry_password}}
MAX_JOB_DURATION_SECONDS={{max_job_duration_seconds}}
{% if metric.enabled %}
METRIC_NAMESPACE=harbor

View File

@ -227,7 +227,6 @@ def parse_yaml_config(config_file_path, with_trivy):
value = config_dict["max_job_duration_hours"]
if not isinstance(value, int) or value < 24:
config_dict["max_job_duration_hours"] = 24
config_dict['max_job_duration_seconds'] = config_dict['max_job_duration_hours'] * 3600
config_dict['job_loggers'] = js_config["job_loggers"]
config_dict['logger_sweeper_duration'] = js_config["logger_sweeper_duration"]
config_dict['jobservice_secret'] = generate_random_string(16)

View File

@ -34,7 +34,6 @@ def prepare_job_service(config_dict):
internal_tls=config_dict['internal_tls'],
max_job_workers=config_dict['max_job_workers'],
max_job_duration_hours=config_dict['max_job_duration_hours'],
max_job_duration_seconds=config_dict['max_job_duration_seconds'],
job_loggers=config_dict['job_loggers'],
logger_sweeper_duration=config_dict['logger_sweeper_duration'],
redis_url=config_dict['redis_url_js'],

View File

@ -42,6 +42,7 @@ const (
jobServiceRedisIdleConnTimeoutSecond = "JOB_SERVICE_POOL_REDIS_CONN_IDLE_TIMEOUT_SECOND"
jobServiceAuthSecret = "JOBSERVICE_SECRET"
coreURL = "CORE_URL"
maxJobDurationSeconds = "MAX_JOB_DURATION_SECONDS"
// JobServiceProtocolHTTPS points to the 'https' protocol
JobServiceProtocolHTTPS = "https"
@ -182,7 +183,19 @@ func (c *Configuration) Load(yamlFilePath string, detectEnv bool) error {
}
// Validate settings
return c.validate()
if err := c.validate(); err != nil {
return err
}
initMaxJobDurationEnv()
return nil
}
func initMaxJobDurationEnv() {
// set environment for gocraft/work if not present in env, it will be used to expire the job service redis key
if len(os.Getenv(maxJobDurationSeconds)) == 0 {
duration := MaxUpdateDuration()
os.Setenv(maxJobDurationSeconds, fmt.Sprintf("%v", duration.Seconds()))
}
}
// GetAuthSecret get the auth secret from the env