Skip to content

Commit 363e4df

Browse files
committed
Explicitly cast task_name as text in cron db tasks
There seems to be a scenario where postgres will implicitly cast the task_name column as a bigint when querying the cron table. This doesn't happen in local testing, but is a periodic issue with remote configurations.
1 parent 27defa2 commit 363e4df

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

backend/db/cron.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package db
22

33
import (
4+
"database/sql"
45
"fmt"
56
"github.com/robfig/cron/v3"
67
"hash/fnv"
@@ -116,7 +117,7 @@ func (task CronTask) getCronString() string {
116117
func (task CronTask) isLocked() bool {
117118
var lockedUntil time.Time
118119

119-
s := `SELECT locked_until FROM cron WHERE task_name=$1`
120+
s := `SELECT locked_until FROM cron WHERE task_name::text=$1`
120121
err := db.QueryRow(s, task.Name).Scan(&lockedUntil)
121122
if err != nil {
122123
log.Printf("Error checking locked_until for task '%s': %v\n", task.Name, err)
@@ -137,7 +138,7 @@ func (task CronTask) runCronTask() {
137138
lockUntil := time.Now().UTC().Add(-time.Second).Add(lockDuration)
138139

139140
err := db.QueryRow("SELECT pg_try_advisory_lock($1)", lockID).Scan(&lockAcquired)
140-
if err != nil {
141+
if err != nil && err != sql.ErrNoRows {
141142
log.Printf("Error acquiring advisory lock: %v\n", err)
142143
return
143144
}

0 commit comments

Comments
 (0)