Skip to content

Commit cd512b9

Browse files
committed
Replace uses of tx.Exec with tx.ExecContext
Signed-off-by: Thomas Stromberg <[email protected]>
1 parent 6a7f85d commit cd512b9

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed

db/hardware.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func (d TinkDB) DeleteFromDB(ctx context.Context, id string) error {
1818
return errors.Wrap(err, "BEGIN transaction")
1919
}
2020

21-
res, err := tx.Exec(`
21+
res, err := tx.ExecContext(ctx, `
2222
UPDATE hardware
2323
SET
2424
deleted_at = NOW()
@@ -47,7 +47,7 @@ func (d TinkDB) InsertIntoDB(ctx context.Context, data string) error {
4747
return errors.Wrap(err, "BEGIN transaction")
4848
}
4949

50-
_, err = tx.Exec(`
50+
_, err = tx.ExecContext(ctx, `
5151
INSERT INTO
5252
hardware (inserted_at, id, data)
5353
VALUES

db/template.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func (d TinkDB) CreateTemplate(ctx context.Context, name string, data string, id
2727
if err != nil {
2828
return errors.Wrap(err, "BEGIN transaction")
2929
}
30-
_, err = tx.Exec(`
30+
_, err = tx.ExecContext(ctx, `
3131
INSERT INTO
3232
template (created_at, updated_at, name, data, id)
3333
VALUES
@@ -107,7 +107,7 @@ func (d TinkDB) DeleteTemplate(ctx context.Context, id string) error {
107107
return errors.Wrap(err, "BEGIN transaction")
108108
}
109109

110-
res, err := tx.Exec(`
110+
res, err := tx.ExecContext(ctx, `
111111
UPDATE template
112112
SET
113113
deleted_at = NOW()
@@ -183,11 +183,11 @@ func (d TinkDB) UpdateTemplate(ctx context.Context, name string, data string, id
183183

184184
switch {
185185
case data == "" && name != "":
186-
_, err = tx.Exec(`UPDATE template SET updated_at = NOW(), name = $2 WHERE id = $1;`, id, name)
186+
_, err = tx.ExecContext(ctx, `UPDATE template SET updated_at = NOW(), name = $2 WHERE id = $1;`, id, name)
187187
case data != "" && name == "":
188-
_, err = tx.Exec(`UPDATE template SET updated_at = NOW(), data = $2 WHERE id = $1;`, id, data)
188+
_, err = tx.ExecContext(ctx, `UPDATE template SET updated_at = NOW(), data = $2 WHERE id = $1;`, id, data)
189189
default:
190-
_, err = tx.Exec(`UPDATE template SET updated_at = NOW(), name = $2, data = $3 WHERE id = $1;`, id, name, data)
190+
_, err = tx.ExecContext(ctx, `UPDATE template SET updated_at = NOW(), name = $2, data = $3 WHERE id = $1;`, id, name, data)
191191
}
192192

193193
if err != nil {

db/workflow.go

+17-17
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func (d TinkDB) CreateWorkflow(ctx context.Context, wf Workflow, data string, id
4444
if err != nil {
4545
return errors.Wrap(err, "failed to create workflow")
4646
}
47-
err = insertInWorkflow(wf, tx)
47+
err = insertInWorkflow(ctx, wf, tx)
4848
if err != nil {
4949
return errors.Wrap(err, "failed to create workflow")
5050
}
@@ -55,8 +55,8 @@ func (d TinkDB) CreateWorkflow(ctx context.Context, wf Workflow, data string, id
5555
return nil
5656
}
5757

58-
func insertInWorkflow(wf Workflow, tx *sql.Tx) error {
59-
_, err := tx.Exec(`
58+
func insertInWorkflow(ctx context.Context, wf Workflow, tx *sql.Tx) error {
59+
_, err := tx.ExecContext(ctx, `
6060
INSERT INTO
6161
workflow (created_at, updated_at, template, devices, id)
6262
VALUES
@@ -72,8 +72,8 @@ func insertInWorkflow(wf Workflow, tx *sql.Tx) error {
7272
return nil
7373
}
7474

75-
func insertIntoWfWorkerTable(wfID uuid.UUID, workerID uuid.UUID, tx *sql.Tx) error {
76-
_, err := tx.Exec(`
75+
func insertIntoWfWorkerTable(ctx context.Context, wfID uuid.UUID, workerID uuid.UUID, tx *sql.Tx) error {
76+
_, err := tx.ExecContext(ctx, `
7777
INSERT INTO
7878
workflow_worker_map (workflow_id, worker_id)
7979
VALUES
@@ -116,7 +116,7 @@ func insertActionList(ctx context.Context, db *sql.DB, yamlData string, id uuid.
116116
return err
117117
}
118118
if uniqueWorkerID != workerUID {
119-
err = insertIntoWfWorkerTable(id, workerUID, tx)
119+
err = insertIntoWfWorkerTable(ctx, id, workerUID, tx)
120120
if err != nil {
121121
return err
122122
}
@@ -173,7 +173,7 @@ func insertActionList(ctx context.Context, db *sql.DB, yamlData string, id uuid.
173173
return err
174174
}
175175

176-
_, err = tx.Exec(`
176+
_, err = tx.ExecContext(ctx, `
177177
INSERT INTO
178178
workflow_state (workflow_id, current_worker, current_task_name, current_action_name, current_action_state, action_list, current_action_index, total_number_of_actions)
179179
VALUES
@@ -203,7 +203,7 @@ func (d TinkDB) InsertIntoWfDataTable(ctx context.Context, req *pb.UpdateWorkflo
203203
return errors.Wrap(err, "BEGIN transaction")
204204
}
205205

206-
_, err = tx.Exec(`
206+
_, err = tx.ExecContext(ctx, `
207207
INSERT INTO
208208
workflow_data (workflow_id, version, metadata, data)
209209
VALUES
@@ -215,7 +215,7 @@ func (d TinkDB) InsertIntoWfDataTable(ctx context.Context, req *pb.UpdateWorkflo
215215

216216
if version > int32(maxVersions) {
217217
cleanVersion := version - int32(maxVersions)
218-
_, err = tx.Exec(`
218+
_, err = tx.ExecContext(ctx, `
219219
UPDATE workflow_data
220220
SET
221221
data = NULL
@@ -375,7 +375,7 @@ func (d TinkDB) DeleteWorkflow(ctx context.Context, id string, _ int32) error {
375375
return errors.Wrap(err, "BEGIN transaction")
376376
}
377377

378-
_, err = tx.Exec(`
378+
_, err = tx.ExecContext(ctx, `
379379
DELETE FROM workflow_worker_map
380380
WHERE
381381
workflow_id = $1;
@@ -384,7 +384,7 @@ func (d TinkDB) DeleteWorkflow(ctx context.Context, id string, _ int32) error {
384384
return errors.Wrap(err, "Delete Workflow Error")
385385
}
386386

387-
_, err = tx.Exec(`
387+
_, err = tx.ExecContext(ctx, `
388388
DELETE FROM workflow_state
389389
WHERE
390390
workflow_id = $1;
@@ -393,7 +393,7 @@ func (d TinkDB) DeleteWorkflow(ctx context.Context, id string, _ int32) error {
393393
return errors.Wrap(err, "Delete Workflow Error")
394394
}
395395

396-
res, err := tx.Exec(`
396+
res, err := tx.ExecContext(ctx, `
397397
UPDATE workflow
398398
SET
399399
deleted_at = NOW()
@@ -469,11 +469,11 @@ func (d TinkDB) UpdateWorkflow(ctx context.Context, wf Workflow, _ int32) error
469469

470470
switch {
471471
case wf.Hardware == "" && wf.Template != "":
472-
_, err = tx.Exec(`UPDATE workflow SET updated_at = NOW(), template = $2 WHERE id = $1;`, wf.ID, wf.Template)
472+
_, err = tx.ExecContext(ctx, `UPDATE workflow SET updated_at = NOW(), template = $2 WHERE id = $1;`, wf.ID, wf.Template)
473473
case wf.Hardware != "" && wf.Template == "":
474-
_, err = tx.Exec(`UPDATE workflow SET updated_at = NOW(), devices = $2 WHERE id = $1;`, wf.ID, wf.Hardware)
474+
_, err = tx.ExecContext(ctx, `UPDATE workflow SET updated_at = NOW(), devices = $2 WHERE id = $1;`, wf.ID, wf.Hardware)
475475
default:
476-
_, err = tx.Exec(`UPDATE workflow SET updated_at = NOW(), template = $2, devices = $3 WHERE id = $1;`, wf.ID, wf.Template, wf.Hardware)
476+
_, err = tx.ExecContext(ctx, `UPDATE workflow SET updated_at = NOW(), template = $2, devices = $3 WHERE id = $1;`, wf.ID, wf.Template, wf.Hardware)
477477
}
478478

479479
if err != nil {
@@ -494,7 +494,7 @@ func (d TinkDB) UpdateWorkflowState(ctx context.Context, wfContext *pb.WorkflowC
494494
return errors.Wrap(err, "BEGIN transaction")
495495
}
496496

497-
_, err = tx.Exec(`
497+
_, err = tx.ExecContext(ctx, `
498498
UPDATE workflow_state
499499
SET current_task_name = $2,
500500
current_action_name = $3,
@@ -581,7 +581,7 @@ func (d TinkDB) InsertIntoWorkflowEventTable(ctx context.Context, wfEvent *pb.Wo
581581
}
582582

583583
// TODO "created_at" field should be set in worker and come in the request
584-
_, err = tx.Exec(`
584+
_, err = tx.ExecContext(ctx, `
585585
INSERT INTO
586586
workflow_event (workflow_id, worker_id, task_name, action_name, execution_time, message, status, created_at)
587587
VALUES

0 commit comments

Comments
 (0)