Skip to content

Commit

Permalink
Add default timeout for go-ora library
Browse files Browse the repository at this point in the history
  • Loading branch information
nxshock committed May 21, 2023
1 parent 67d0cf8 commit ab02e12
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions consts.go
Original file line number Diff line number Diff line change
@@ -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}}"
)
6 changes: 5 additions & 1 deletion job.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"context"
"database/sql"
"errors"
"fmt"
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit ab02e12

Please sign in to comment.