Something went wrong on our end
Select Git revision
persistence.go
-
Volker Schukai authoredVolker Schukai authored
persistence.go 9.13 KiB
package jobqueue
import (
"encoding/json"
"fmt"
"gopkg.in/yaml.v3"
"gorm.io/gorm"
"io"
"os"
"strings"
"time"
)
type JobPersistence struct {
ID JobID `yaml:"id" json:"id" gorm:"type:varchar(255);primaryKey"`
Description string `yaml:"description" json:"description" gorm:"column:description"`
Priority Priority `yaml:"priority" json:"priority" gorm:"column:priority"`
Timeout time.Duration `yaml:"timeout" json:"timeout" gorm:"column:timeout"`
MaxRetries uint `yaml:"maxRetries" json:"maxRetries" gorm:"column:max_retries"`
RetryDelay time.Duration `yaml:"retryDelay" json:"retryDelay" gorm:"column:retry_delay"`
Dependencies []JobID `yaml:"dependencies" json:"dependencies,omitempty" gorm:"column:dependencies;type:json"`
Runnable RunnableImport `yaml:"runnable" json:"runnable" gorm:"embedded;embeddedPrefix:runnable_"`
Scheduler SchedulerPersistence `yaml:"scheduler" json:"scheduler,omitempty" gorm:"embedded;embeddedPrefix:scheduler_"`
Pause bool `yaml:"pause" json:"pause" gorm:"column:pause"`
PauseReason string `yaml:"pauseReason" json:"pauseReason" gorm:"column:pause_reason"`
PauseUntil time.Time `yaml:"pauseUntil" json:"pauseUntil" gorm:"column:pause_until"`
Logs []JobLog `gorm:"foreignKey:JobID;references:ID" json:"-" yaml:"-"`
Stats JobStats `gorm:"foreignKey:JobID" json:"stats" yaml:"stats"`
CreatedAt time.Time `gorm:"column:created_at" json:"created_at" yaml:"created_at"`
UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at" yaml:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;index" json:"-" yaml:"-"`
}
func (jp JobPersistence) GetLogs() []JobLog {
return jp.Logs
}
func (jp JobPersistence) GetStats() JobStats {
return jp.Stats
}
func (jp JobPersistence) GetID() JobID {
return jp.ID
}
func (jp JobPersistence) GetPersistence() JobPersistence {
return jp
}
func (jp JobPersistence) GetDescription() string {
return jp.Description
}
func (jp JobPersistence) GetPriority() Priority {
return jp.Priority
}
func (jp JobPersistence) GetTimeout() time.Duration {
return jp.Timeout
}
func (JobPersistence) TableName() string {
return globalTableNamePrefix + "jobs"
}
type RunnableImport struct {
Type string `yaml:"type" json:"type" gorm:"column:type"`