Skip to content
Snippets Groups Projects
Select Git revision
  • 752d3af553a93858a3ea54c4dfa38949953183bc
  • master default protected
  • v1.23.2
  • v1.23.1
  • v1.23.0
  • v1.22.0
  • v1.21.1
  • v1.21.0
  • v1.20.3
  • v1.20.2
  • v1.20.1
  • v1.20.0
  • v1.19.4
  • v1.19.3
  • v1.19.2
  • v1.19.1
  • v1.19.0
  • v1.18.2
  • v1.18.1
  • v1.18.0
  • v1.17.0
  • v1.16.1
22 results

job.go

Blame
  • job.go 8.12 KiB
    // Copyright 2023 schukai GmbH
    // SPDX-License-Identifier: AGPL-3.0
    
    package jobqueue
    
    import (
    	"context"
    	"os"
    	"sync"
    	"time"
    )
    
    type JobID string
    
    // String returns the string representation of a JobID
    func (id JobID) String() string {
    	return string(id)
    }
    
    type GetResultAndError interface {
    	GetResult() string
    	GetError() (string, int)
    }
    
    // Priority is the priority of a job
    type Priority int
    
    const (
    	PriorityLow Priority = iota
    	PriorityDefault
    	PriorityHigh
    	PriorityCritical
    )
    
    // Job is a job that can be executed
    type Job[T any] struct {
    	id          JobID
    	description string
    	priority    Priority
    
    	timeout    *time.Duration
    	maxRetries uint
    	retryDelay *time.Duration
    
    	scheduler Scheduler
    
    	pause       bool
    	pauseReason string
    	pauseUntil  *time.Time
    
    	dependencies []JobID
    
    	mu sync.Mutex
    
    	runner Runnable[T]
    
    	stats *JobStats
    	logs  []JobLog
    }
    
    // NewJob creates a new job with the given id and runner
    func NewJob[T any](id JobID, runner Runnable[T]) *Job[T] {
    	return &Job[T]{
    		id:       id,
    		runner:   runner,
    		priority: PriorityDefault,
    		logs:     make([]JobLog, 0),
    		stats:    &JobStats{},
    	}
    }