Skip to content

Commit f692907

Browse files
authored
Merge pull request #542 from cybertec-postgresql/541-error-failed-to-set-current-task-contexttx-is-closed
[-] fix executor context for pgengine.SetCurrentTaskContext(), fixes #541
2 parents f1a3f11 + 784234a commit f692907

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

internal/pgengine/bootstrap.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ type PgEngine struct {
6767
// where all IDs are the same across all running containers, e.g. 1
6868
func (pge *PgEngine) Getsid() int32 {
6969
if pge.sid == 0 {
70-
rand.Seed(time.Now().UnixNano())
71-
pge.sid = rand.Int31()
70+
r := rand.New(rand.NewSource(time.Now().UnixNano()))
71+
pge.sid = r.Int31()
7272
}
7373
return pge.sid
7474
}

internal/pgengine/transaction.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ func (pge *PgEngine) ExecuteSQLTask(ctx context.Context, tx pgx.Tx, task *ChainT
172172
}
173173
}
174174

175-
pge.SetCurrentTaskContext(ctx, execTx, task.TaskID)
175+
pge.SetCurrentTaskContext(ctx, executor, task.TaskID)
176176
out, err = pge.ExecuteSQLCommand(ctx, executor, task.Script, paramValues)
177177

178178
if err != nil && task.IgnoreError && !task.Autonomous {
@@ -282,10 +282,10 @@ func (pge *PgEngine) ResetRole(ctx context.Context, tx pgx.Tx) {
282282
}
283283

284284
// SetCurrentTaskContext - set the working transaction "pg_timetable.current_task_id" run-time parameter
285-
func (pge *PgEngine) SetCurrentTaskContext(ctx context.Context, tx pgx.Tx, taskID int) {
285+
func (pge *PgEngine) SetCurrentTaskContext(ctx context.Context, executor executor, taskID int) {
286286
l := log.GetLogger(ctx)
287287
l.Debug("Setting current task context to ", taskID)
288-
_, err := tx.Exec(ctx, "SELECT set_config('pg_timetable.current_task_id', $1, true)", strconv.Itoa(taskID))
288+
_, err := executor.Exec(ctx, "SELECT set_config('pg_timetable.current_task_id', $1, true)", strconv.Itoa(taskID))
289289
if err != nil {
290290
l.WithError(err).Error("Failed to set current task context", err)
291291
}

0 commit comments

Comments
 (0)