model

package
v0.0.0-...-e71ddb8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 9, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DB *gorm.DB

DB gorm DB

Functions

func ConnectDataBase

func ConnectDataBase(cduleConfig *pkg.CduleConfig)

ConnectDataBase to create a database connection

func Migrate

func Migrate(db *gorm.DB)

Migrate database schema

Types

type CduleRepository

type CduleRepository interface {
	CreateWorker(worker *Worker) (*Worker, error)
	UpdateWorker(worker *Worker) (*Worker, error)
	GetWorker(workerID string) (*Worker, error)
	GetWorkers() ([]Worker, error)
	GetAliveWorkers() ([]Worker, error)
	DeleteWorker(workerID string) (*Worker, error)

	CreateJob(job *Job) (*Job, error)
	UpdateJob(job *Job) (*Job, error)
	SaveJob(job *Job) (*Job, error)
	GetJob(jobID int64) (*Job, error)
	GetJobByName(name string) (*Job, error)
	GetRepeatingJobByName(name string) (*Job, error)
	DeleteJob(jobID int64) (*Job, error)

	CreateJobHistory(jobHistory *JobHistory) (*JobHistory, error)
	UpdateJobHistory(jobHistory *JobHistory) (*JobHistory, error)
	GetJobHistory(jobID int64) ([]JobHistory, error)
	GetJobHistoryWithLimit(jobID int64, limit int) ([]JobHistory, error)
	GetJobHistoryForSchedule(scheduleID int64) (*JobHistory, error)
	DeleteJobHistory(jobID int64) ([]JobHistory, error)

	CreateSchedule(schedule *Schedule) (*Schedule, error)
	UpdateSchedule(schedule *Schedule) (*Schedule, error)
	GetSchedule(executionID int64) (*Schedule, error)
	GetScheduleByID(scheduleID int64) (*Schedule, error)
	GetScheduleBetween(scheduleStart, scheduleEnd int64, workerID string) ([]Schedule, error)
	GetScheduleBefore(nanoUnix int64, workerID string) ([]Schedule, error)
	GetPassedSchedule(nanoUnix int64, workerID string, onlyOnces bool) ([]Schedule, error)
	GetSchedulesForJob(jobID int64) ([]Schedule, error)
	GetSchedulesForWorker(workerID string) ([]Schedule, error)
	GetSchedulesForJobName(jobName string, subName string) ([]Schedule, error)
	DeleteScheduleForJob(jobID int64) ([]Schedule, error)
	DeleteScheduleForWorker(workerID string) ([]Schedule, error)
	DeleteScheduleForJobName(jobName string, subName string) ([]Schedule, error)

	GetWorkerCountByJobID(jobID int64) ([]WorkerJobCount, error)
}

CduleRepository cdule repository interface

func NewCduleRepository

func NewCduleRepository(db *gorm.DB) CduleRepository

NewCduleRepository cdule repository

type Job

type Job struct {
	Model
	JobName        string `gorm:"index" json:"job_name"`
	SubName        string `json:"sub_name"`
	CronExpression string `json:"cron"`
	Expired        bool   `json:"expired"`
	Once           bool   `json:"once"`
	JobData        string `json:"job_data"`
}

Job struct

type JobHistory

type JobHistory struct {
	Model
	JobID      int64     `json:"job_id"`
	Job        Job       `gorm:"foreignKey:job_id;references:id;constraint:OnDelete:CASCADE"`
	ScheduleID int64     `json:"schedule_id"`
	Schedule   Schedule  `gorm:"foreignKey:schedule_id;references:id;constraint:OnDelete:CASCADE"`
	Status     JobStatus `json:"status"`
	WorkerID   string    `json:"worker_id"`
	RetryCount int       `json:"retry_count"`
}

JobHistory struct

type JobStatus

type JobStatus string

JobStatus for job status

const (
	// JobStatusNew status NEW
	JobStatusNew JobStatus = "NEW"
	// JobStatusInProgress status IN_PROGRESS
	JobStatusInProgress JobStatus = "IN_PROGRESS"
	// JobStatusCompleted status COMPLETED
	JobStatusCompleted JobStatus = "COMPLETED"
	// JobStatusFailed status FAILED
	JobStatusFailed JobStatus = "FAILED"
)

type Model

type Model struct {
	ID        int64 `gorm:"primarykey"`
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt `gorm:"column:deleted_at; index"`
}

Model common model

type Repositories

type Repositories struct {
	CduleRepository CduleRepository
	DB              *gorm.DB
}

Repositories struct

var CduleRepos *Repositories

CduleRepos repositories

type Schedule

type Schedule struct {
	Model
	ExecutionID int64  `json:"execution_id"`
	JobID       int64  `json:"job_id"`
	Job         Job    `gorm:"foreignKey:job_id;references:id;constraint:OnDelete:CASCADE"`
	WorkerID    string `json:"worker_id"`
	JobData     string `json:"job_data"`
}

Schedule used by Execution Routine to execute a scheduled job in the evert one minute duration

type Worker

type Worker struct {
	WorkerID  string `gorm:"primaryKey" json:"worker_id"`
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt `gorm:"index"`
}

Worker Node health check via the heartbeat

type WorkerJobCount

type WorkerJobCount struct {
	WorkerID string `json:"worker_id"`
	Count    int64  `json:"count"`
}

WorkerJobCount struct

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL