Something went wrong on our end
Select Git revision
-
Volker Schukai authoredVolker Schukai authored
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{},
}
}