github.com/Axway/agent-sdk@v1.1.101/pkg/jobs/definitions.go (about)

     1  package jobs
     2  
     3  import "time"
     4  
     5  const defaultRetryInterval = 30 * time.Second
     6  
     7  //Job -  the job interface, users of this library need to implement these
     8  type Job interface {
     9  	Execute() error
    10  	Status() error
    11  	Ready() bool
    12  }
    13  
    14  //JobExecution - the wrapper interface for every type of job
    15  //               controls the calling the methods defined in the Job interface
    16  type JobExecution interface {
    17  	GetStatus() JobStatus
    18  	GetID() string
    19  	GetName() string
    20  	Ready() bool
    21  	GetJob() JobExecution
    22  	Lock()
    23  	Unlock()
    24  	start()
    25  	stop()
    26  	getConsecutiveFails() int
    27  	updateStatus() JobStatus
    28  }
    29  
    30  //JobStatus - integer to represent the status of the job
    31  type JobStatus int
    32  
    33  const (
    34  	//JobStatusInitializing - Initializing
    35  	JobStatusInitializing JobStatus = iota
    36  	//JobStatusRunning - Running
    37  	JobStatusRunning
    38  	//JobStatusRetrying - Retrying
    39  	JobStatusRetrying
    40  	//JobStatusStopped - Stopped
    41  	JobStatusStopped
    42  	//JobStatusFailed - Failed
    43  	JobStatusFailed
    44  	//JobStatusFinished - Finished
    45  	JobStatusFinished
    46  )
    47  
    48  //statusToString - maps the PoolStatus integer to a string representation
    49  var jobStatusToString = map[JobStatus]string{
    50  	JobStatusInitializing: "Initializing",
    51  	JobStatusRunning:      "Running",
    52  	JobStatusRetrying:     "Retrying",
    53  	JobStatusStopped:      "Stopped",
    54  	JobStatusFailed:       "Failed",
    55  	JobStatusFinished:     "Finished",
    56  }
    57  
    58  func (s JobStatus) String() string {
    59  	return jobStatusToString[s]
    60  }
    61  
    62  //PoolStatus - integer to represent the status of the jobs in the pool
    63  type PoolStatus int
    64  
    65  const (
    66  	//PoolStatusInitializing - Initializing
    67  	PoolStatusInitializing PoolStatus = iota
    68  	//PoolStatusRunning - Running
    69  	PoolStatusRunning
    70  	//PoolStatusStopped - Stopped
    71  	PoolStatusStopped
    72  )
    73  
    74  //poolStatusToString - maps the PoolStatus integer to a string representation
    75  var poolStatusToString = map[PoolStatus]string{
    76  	PoolStatusInitializing: "Initializing",
    77  	PoolStatusRunning:      "Running",
    78  	PoolStatusStopped:      "Stopped",
    79  }
    80  
    81  func (s PoolStatus) String() string {
    82  	return poolStatusToString[s]
    83  }
    84  
    85  // Job type strings
    86  const (
    87  	JobTypeSingleRun        = "single run"
    88  	JobTypeRetry            = "retry"
    89  	JobTypeInterval         = "interval"
    90  	JobTypeChannel          = "channel"
    91  	JobTypeDetachedChannel  = "detached channel"
    92  	JobTypeDetachedInterval = "detached interval"
    93  	JobTypeScheduled        = "scheduled"
    94  )