Skip to content

Commit

Permalink
Merge pull request #542 from cybertec-postgresql/541-error-failed-to-…
Browse files Browse the repository at this point in the history
…set-current-task-contexttx-is-closed

[-] fix executor context for pgengine.SetCurrentTaskContext(), fixes #541
  • Loading branch information
pashagolub committed Feb 23, 2023
2 parents f1a3f11 + 784234a commit f692907
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions internal/pgengine/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ type PgEngine struct {
// where all IDs are the same across all running containers, e.g. 1
func (pge *PgEngine) Getsid() int32 {
if pge.sid == 0 {
rand.Seed(time.Now().UnixNano())
pge.sid = rand.Int31()
r := rand.New(rand.NewSource(time.Now().UnixNano()))
pge.sid = r.Int31()
}
return pge.sid
}
Expand Down
6 changes: 3 additions & 3 deletions internal/pgengine/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (pge *PgEngine) ExecuteSQLTask(ctx context.Context, tx pgx.Tx, task *ChainT
}
}

pge.SetCurrentTaskContext(ctx, execTx, task.TaskID)
pge.SetCurrentTaskContext(ctx, executor, task.TaskID)
out, err = pge.ExecuteSQLCommand(ctx, executor, task.Script, paramValues)

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

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

0 comments on commit f692907

Please sign in to comment.