Skip to content
Snippets Groups Projects
Select Git revision
  • d5e80d16f2e16cc5311ad320797dcd20fafef5c8
  • master default protected
  • 1.31
  • 4.28.0
  • 4.27.0
  • 4.26.0
  • 4.25.5
  • 4.25.4
  • 4.25.3
  • 4.25.2
  • 4.25.1
  • 4.25.0
  • 4.24.3
  • 4.24.2
  • 4.24.1
  • 4.24.0
  • 4.23.6
  • 4.23.5
  • 4.23.4
  • 4.23.3
  • 4.23.2
  • 4.23.1
  • 4.23.0
23 results

Makefile

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{},
    	}
    }