Skip to content
Snippets Groups Projects
job-stat.go 1.05 KiB
// Copyright 2023 schukai GmbH
// SPDX-License-Identifier: AGPL-3.0

package jobqueue

import (
	"gorm.io/gorm"
	"time"
)

// important: if you want to add fields to this struct, you have to add them to the ResetStats() method as well
type JobStats struct {
	JobID        JobID       `json:"jobId" gorm:"primaryKey"`
	RunCount     int         `json:"runCount"`
	SuccessCount int         `json:"successCount"`
	ErrorCount   int         `json:"errorCount"`
	TimeMetrics  TimeMetrics `json:"timeMetrics" gorm:"embedded;embeddedPrefix:time_metrics_"`

	CreatedAt time.Time      `gorm:"column:created_at" json:"createdAt" yaml:"createdAt"`
	UpdatedAt time.Time      `gorm:"column:updated_at" json:"updatedAt" yaml:"updatedAt"`
	DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;index" json:"-" yaml:"-"`
}

type TimeMetrics struct {
	AvgRunTime   time.Duration `json:"avg"`
	MaxRunTime   time.Duration `json:"max"`
	MinRunTime   time.Duration `json:"min"`
	TotalRunTime time.Duration `json:"total"`
}

func (JobStats) TableName() string {
	return globalTableNamePrefix + "job_stats"
}