Skip to content
Snippets Groups Projects
Verified Commit 9d774f0a authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

feat: new runJob method #32

parent 5e6046be
No related branches found
No related tags found
No related merge requests found
......@@ -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:"-"`
}
......
......@@ -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:"-"`
}
......
......@@ -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()
......
......@@ -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:"-"`
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment