mirror of
https://github.com/semaphoreui/semaphore.git
synced 2024-11-23 12:30:41 +01:00
fix(be): convert time to utc before db operations
This commit is contained in:
parent
24bc4a83b8
commit
018dd93fcb
19
db/Task.go
19
db/Task.go
@ -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
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user