From ab02e120ccb19ee0ffedadcc6963560c27c62bd4 Mon Sep 17 00:00:00 2001 From: nxshock Date: Sun, 21 May 2023 15:20:25 +0500 Subject: [PATCH] Add default timeout for go-ora library --- consts.go | 4 ++++ job.go | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/consts.go b/consts.go index cbc1aa4..408ac35 100644 --- a/consts.go +++ b/consts.go @@ -1,8 +1,12 @@ package main +import "time" + const ( defaultConfigFileName = "gron.conf" + defaultDbTimeout = 24 * time.Hour + defaultOnSuccessMessageFmt = "Job {{.JobName}} finished." defaultOnErrorMessageFmt = "Job {{.JobName}} failed:\n\n{{.Error}}" ) diff --git a/job.go b/job.go index f3e7ca4..d648028 100644 --- a/job.go +++ b/job.go @@ -1,6 +1,7 @@ package main import ( + "context" "database/sql" "errors" "fmt" @@ -245,7 +246,10 @@ func (j *Job) runSql(jobLogFile *os.File) error { } defer db.Close() - _, err = db.Exec(j.JobConfig.SqlText) + ctx, cancel := context.WithTimeout(context.Background(), defaultDbTimeout) + defer cancel() + + _, err = db.ExecContext(ctx, j.JobConfig.SqlText) if err != nil { return err }