diff --git a/job-log.go b/job-log.go index 53b8bb57a4992460bb304a6972d64c2a057ebb4f..a59ef8f03566f483650a13f8640f157ff1e0d9f4 100644 --- a/job-log.go +++ b/job-log.go @@ -6,20 +6,20 @@ import ( ) type JobLog struct { - LogID uint `gorm:"primarykey;autoIncrement:true" json:"log_id"` - JobID JobID `json:"job_id" gorm:"type:varchar(255);foreignKey:JobID;references:ID"` - ProcessID int `json:"process_id"` - StartTime time.Time `json:"start_time"` - EndTime time.Time `json:"end_time"` - ExitCode int `json:"exit_code"` + LogID uint `gorm:"primarykey;autoIncrement:true" json:"logId"` + JobID JobID `json:"jobId" gorm:"type:varchar(255);foreignKey:JobID;references:ID"` + ProcessID int `json:"processId"` + StartTime time.Time `json:"startTime"` + EndTime time.Time `json:"endTime"` + ExitCode int `json:"exitCode"` Result string `json:"output" gorm:"type:TEXT"` // Assuming serialized JSON for any type - ResourceUsage ResourceUsage `json:"resource_usage" gorm:"embedded;embeddedPrefix:resource_usage_"` + ResourceUsage ResourceUsage `json:"resourceUsage" gorm:"embedded;embeddedPrefix:resource_usage_"` IO IO `json:"io" gorm:"embedded;embeddedPrefix:io_"` - ErrorMsg string `json:"error_msg"` - IsSuccessful bool `json:"is_successful"` + ErrorMsg string `json:"errorMsg"` + IsSuccessful bool `json:"isSuccessful"` - 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"` + 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:"-"` } diff --git a/job-stat.go b/job-stat.go index 2a784cccbee25ac412bbd6327504aa491f1fe96b..75c643ad95276b0f15c1df30d64239b22e39270c 100644 --- a/job-stat.go +++ b/job-stat.go @@ -7,14 +7,14 @@ import ( // 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:"job_id" gorm:"primaryKey"` - RunCount int `json:"run_count"` - SuccessCount int `json:"success_count"` - ErrorCount int `json:"error_count"` - TimeMetrics TimeMetrics `json:"time_metrics" gorm:"embedded;embeddedPrefix:time_metrics_"` + 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:"created_at" yaml:"created_at"` - UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at" yaml:"updated_at"` + 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:"-"` } diff --git a/manager.go b/manager.go index 99c60c0649b67212ac86179fbb48efcbaf9695a9..9056c3cf728501fd3f71f25c0fbc8375105d069e 100644 --- a/manager.go +++ b/manager.go @@ -481,12 +481,30 @@ func (m *Manager) SetLogger(logger Logger) *Manager { return m } +// GetLogger returns the logger func (m *Manager) GetLogger() Logger { m.mu.Lock() defer m.mu.Unlock() return m.logger } +// RunJob runs a job immediately and does not schedule it +func (m *Manager) RunJob(job GenericJob) error { + m.mu.Lock() + defer m.mu.Unlock() + + if m.state != ManagerStateRunning { + return ErrManagerNotRunning + } + + if !job.IsPaused() { + m.eventBus.Publish(QueueJob, job) + } + + return nil + +} + // ScheduleJob schedules a job func (m *Manager) ScheduleJob(job GenericJob, scheduler Scheduler) error { m.mu.Lock() diff --git a/persistence.go b/persistence.go index 1921cb8b438b4d96b5751010473e07681df8636f..9b09bedafa05be2eba924fa8c6585eb04909c097 100644 --- a/persistence.go +++ b/persistence.go @@ -30,8 +30,8 @@ type JobPersistence struct { 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"` + 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:"-"` }