Skip to content

Commit e92f85e

Browse files
committed
feat: add AddTask method to Job and refactor SQL script handling in runSingleTask
1 parent 5f13f1b commit e92f85e

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

internal/process/orchestrator.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,7 @@ func SupplementaryJobQueue(config *config.Config) (*JobQueue, error) {
133133

134134
return queue, nil
135135
}
136+
137+
func (j *Job) AddTask(task *Task) {
138+
j.Tasks = append(j.Tasks, task)
139+
}

internal/process/runner.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,10 @@ func (r *Runner) RunTaskWithRetry(task *Task, conn *pgxpool.Pool, config *config
8686
return fmt.Errorf("task %s failed after %d retries: %w", task.TaskType, maxRetries, lastErr)
8787
}
8888

89-
// runSingleTask reads the SQL file and executes it against the database.
90-
// task.LodLevel drives which LOD schema and building IDs are used — -1 means no LOD context (schema setup, functions, etc.).
89+
// runSingleTask is the internal method that actually executes a task
9190
func (r *Runner) runSingleTask(task *Task, conn *pgxpool.Pool, workerID int) error {
9291
utils.Debug.Printf("[Worker %d] Starting task: %s (SQL file: %s)", workerID, task.TaskType, task.SQLFile)
93-
94-
data, err := os.ReadFile(task.SQLFile)
92+
sqlScript, err := r.getSQLScript(task.SQLFile)
9593
if err != nil {
9694
return fmt.Errorf("failed to read SQL file %s: %w", task.SQLFile, err)
9795
}
@@ -118,6 +116,14 @@ func (r *Runner) runSingleTask(task *Task, conn *pgxpool.Pool, workerID int) err
118116
return nil
119117
}
120118

119+
func (r *Runner) getSQLScript(path string) (string, error) {
120+
data, err := os.ReadFile(path)
121+
if err != nil {
122+
return "", err
123+
}
124+
return string(data), nil
125+
}
126+
121127
// isDeadlockError checks if the error is a PostgreSQL deadlock error
122128
func isDeadlockError(err error) bool {
123129
if err == nil {
@@ -128,4 +134,3 @@ func isDeadlockError(err error) bool {
128134
return strings.Contains(errStr, "deadlock detected") ||
129135
strings.Contains(errStr, "sqlstate 40p01")
130136
}
131-

0 commit comments

Comments
 (0)