fix(be): convert time to utc before db operations

This commit is contained in:
Denis Gukov 2024-07-22 01:21:54 +05:00
parent 24bc4a83b8
commit 018dd93fcb
2 changed files with 25 additions and 1 deletions

View File

@ -2,6 +2,7 @@ package db
import (
"fmt"
"github.com/go-gorp/gorp/v3"
"time"
"github.com/ansible-semaphore/semaphore/pkg/task_logger"
@ -51,6 +52,24 @@ type Task struct {
InventoryID *int `db:"inventory_id" json:"inventory_id"`
}
func (task *Task) PreInsert(gorp.SqlExecutor) error {
task.Created = task.Created.UTC()
return nil
}
func (task *Task) PreUpdate(gorp.SqlExecutor) error {
if task.Start != nil {
start := task.Start.UTC()
task.Start = &start
}
if task.End != nil {
end := task.End.UTC()
task.End = &end
}
return nil
}
func (task *Task) GetIncomingVersion(d Store) *string {
if task.BuildTaskID == nil {
return nil

View File

@ -92,7 +92,12 @@ func (d *SqlDb) CreateTask(task db.Task, maxTasks int) (newTask db.Task, err err
}
func (d *SqlDb) UpdateTask(task db.Task) error {
_, err := d.exec(
err := task.PreUpdate(d.sql)
if err != nil {
return err
}
_, err = d.exec(
"update task set status=?, start=?, `end`=? where id=?",
task.Status,
task.Start,