github.com/blend/go-sdk@v1.20220411.3/cron/job_config.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package cron 9 10 import ( 11 "context" 12 "time" 13 14 "github.com/blend/go-sdk/configutil" 15 "github.com/blend/go-sdk/ref" 16 ) 17 18 var ( 19 _ configutil.Resolver = (*JobConfig)(nil) 20 ) 21 22 // JobConfig is a configuration set for a job. 23 type JobConfig struct { 24 // Disabled determines if the job should be automatically scheduled or not. 25 Disabled *bool `json:"disabled" yaml:"disabled"` 26 // Description is an optional string to describe what the job does. 27 Description string `json:"description" yaml:"description"` 28 // Labels define extra metadata that can be used to filter jobs. 29 Labels map[string]string `json:"labels" yaml:"labels"` 30 // ParameterValues act as default parameters for a given job. 31 ParameterValues JobParameters `json:"parameterValues" yaml:"parameterValues"` 32 // Timeout represents the abort threshold for the job. 33 Timeout time.Duration `json:"timeout" yaml:"timeout"` 34 // ShutdownGracePeriod represents the time a job is given to clean itself up. 35 ShutdownGracePeriod time.Duration `json:"shutdownGracePeriod" yaml:"shutdownGracePeriod"` 36 // SkipLoggerTrigger skips triggering logger events if it is set to true. 37 SkipLoggerTrigger bool `json:"skipLoggerTrigger" yaml:"skipLoggerTrigger"` 38 } 39 40 // Resolve implements configutil.Resolver. 41 func (jc *JobConfig) Resolve(ctx context.Context) error { 42 return configutil.Resolve(ctx, 43 configutil.SetBoolPtr(&jc.Disabled, configutil.Bool(jc.Disabled), configutil.Bool(ref.Bool(DefaultDisabled))), 44 configutil.SetDuration(&jc.Timeout, configutil.Duration(jc.Timeout), configutil.Duration(DefaultTimeout)), 45 configutil.SetDuration(&jc.ShutdownGracePeriod, configutil.Duration(jc.ShutdownGracePeriod), configutil.Duration(DefaultShutdownGracePeriod)), 46 ) 47 } 48 49 // DisabledOrDefault returns a value or a default. 50 func (jc JobConfig) DisabledOrDefault() bool { 51 if jc.Disabled != nil { 52 return *jc.Disabled 53 } 54 return DefaultDisabled 55 } 56 57 // TimeoutOrDefault returns a value or a default. 58 func (jc JobConfig) TimeoutOrDefault() time.Duration { 59 if jc.Timeout > 0 { 60 return jc.Timeout 61 } 62 return DefaultTimeout 63 } 64 65 // ShutdownGracePeriodOrDefault returns a value or a default. 66 func (jc JobConfig) ShutdownGracePeriodOrDefault() time.Duration { 67 if jc.ShutdownGracePeriod > 0 { 68 return jc.ShutdownGracePeriod 69 } 70 return DefaultShutdownGracePeriod 71 }