This commit is contained in:
che
2026-07-12 20:42:21 +05:00
parent b815cde04c
commit e3490e5d2e
23 changed files with 1568 additions and 538 deletions
+4 -8
View File
@@ -10,7 +10,6 @@ import (
"sync"
"time"
"control/analize"
"github.com/gocarina/gocsv"
"gorm.io/gorm"
)
@@ -26,11 +25,13 @@ func exists(path string) (bool, error) {
return false, err
}
const BASE_DIR = "./data"
func worker(id int, jobs <-chan ControlCase, ctx context.Context, db *gorm.DB) {
for j := range jobs {
fmt.Printf("Worker %d started job %d \n", id, j.ID)
p := j.Params
p.FolderPath = filepath.Join(".", fmt.Sprintf("%d", p.ID))
p.FolderPath = filepath.Join(BASE_DIR, fmt.Sprintf("%d", p.ID))
exists, err := p.Exist()
if err != nil {
@@ -49,12 +50,6 @@ func worker(id int, jobs <-chan ControlCase, ctx context.Context, db *gorm.DB) {
}
}
csvPath := filepath.Join(p.FolderPath, "foo.csv")
if _, err := analize.AnalyzeCSV(db, j.ID, j.Name, csvPath); err != nil {
fmt.Printf("Worker %d failed to analyze job %d: %v\n", id, j.ID, err)
continue
}
j.Status = "R"
if err := db.Model(&ControlCase{}).Where("id = ?", j.ID).Update("status", j.Status).Error; err != nil {
fmt.Printf("Worker %d failed to update status for job %d: %v\n", id, j.ID, err)
@@ -92,6 +87,7 @@ func readFromDb(db *gorm.DB) []ControlCase {
_ = db.
Where("status IN ?", statuses).
Preload("Params").
Preload("Params.InitialCondition").
Find(&cases).Error
return cases
}