go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/sdk/cron/job_config.go (about)

     1  /*
     2  
     3  Copyright (c) 2023 - Present. Will Charczuk. All rights reserved.
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file at the root of the repository.
     5  
     6  */
     7  
     8  package cron
     9  
    10  import (
    11  	"time"
    12  )
    13  
    14  // JobConfig is a configuration set for a job.
    15  type JobConfig struct {
    16  	// Disabled determines if the job should be automatically scheduled or not.
    17  	Disabled bool `json:"disabled" yaml:"disabled"`
    18  	// Description is an optional string to describe what the job does.
    19  	Description string `json:"description" yaml:"description"`
    20  	// Labels define extra metadata that can be used to filter jobs.
    21  	Labels map[string]string `json:"labels" yaml:"labels"`
    22  	// ParameterValues act as default parameters for a given job.
    23  	ParameterValues JobParameters `json:"parameterValues" yaml:"parameterValues"`
    24  	// Timeout represents the abort threshold for the job.
    25  	Timeout time.Duration `json:"timeout" yaml:"timeout"`
    26  	// ShutdownGracePeriod represents the time a job is given to clean itself up.
    27  	ShutdownGracePeriod time.Duration `json:"shutdownGracePeriod" yaml:"shutdownGracePeriod"`
    28  	// SkipLoggerTrigger skips triggering logger events if it is set to true.
    29  	SkipLoggerTrigger bool `json:"skipLoggerTrigger" yaml:"skipLoggerTrigger"`
    30  }
    31  
    32  // TimeoutOrDefault returns a value or a default.
    33  func (jc JobConfig) TimeoutOrDefault() time.Duration {
    34  	if jc.Timeout > 0 {
    35  		return jc.Timeout
    36  	}
    37  	return DefaultTimeout
    38  }
    39  
    40  // ShutdownGracePeriodOrDefault returns a value or a default.
    41  func (jc JobConfig) ShutdownGracePeriodOrDefault() time.Duration {
    42  	if jc.ShutdownGracePeriod > 0 {
    43  		return jc.ShutdownGracePeriod
    44  	}
    45  	return DefaultShutdownGracePeriod
    46  }