Skip to content
Snippets Groups Projects
Select Git revision
  • 3cb0b5977f840ce4cd0e1274b3545a08621d9800
  • 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

persistence.go

Blame
  • 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"`