Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion api/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ servers:

info:
title: opensvc collector api
version: 1.0.10
version: 1.0.11

paths:
/feed/daemon/ping:
Expand Down Expand Up @@ -382,6 +382,7 @@ components:
description: the opensvc client data version
begin:
type: string
description: begin action timestamp in RFC3339Nano format
cron:
type: boolean
session_uuid:
Expand All @@ -394,6 +395,7 @@ components:
type: string
end:
type: string
description: end action timestamp in RFC3339Nano format
status_log:
type: string
status:
Expand Down
69 changes: 35 additions & 34 deletions api/codegen_server_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 14 additions & 10 deletions api/codegen_type_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 0 additions & 34 deletions cdb/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package cdb
import (
"fmt"
"log/slog"
"strconv"
"strings"
"time"
)

Expand All @@ -15,35 +13,3 @@ func logDuration(s string, begin time.Time) {
func logDurationInfo(s string, begin time.Time) {
slog.Info(fmt.Sprintf("STAT: %s elapse: %s", s, time.Since(begin)))
}

// Todo : to move elsewhere...
// Tz can be either a timezone name (ex: "Europe/Paris") or a UTC offset (ex: "+01:00")
func ParseTimeWithTimezone(dateStr, tzStr string) (time.Time, error) {
const timeFormat = "2006-01-02 15:04:05"

// Named Tz
if loc, err := time.LoadLocation(tzStr); err == nil {
return time.ParseInLocation(timeFormat, dateStr, loc)
}

// Offset Tz
tzStr = strings.TrimSpace(tzStr)
if tzStr != "" && (tzStr[0] == '+' || tzStr[0] == '-') {
parts := strings.Split(tzStr[1:], ":")
if len(parts) >= 2 {
hours, errH := strconv.Atoi(parts[0])
minutes, errM := strconv.Atoi(parts[1])
if errH == nil && errM == nil {
offset := hours*3600 + minutes*60
if tzStr[0] == '-' {
offset = -offset
}
loc := time.FixedZone(tzStr, offset)
return time.ParseInLocation(timeFormat, dateStr, loc)
}
}
}

// Fallback
return time.Parse(timeFormat, dateStr)
}
6 changes: 3 additions & 3 deletions worker/job_feed_instance_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (d *jobFeedInstanceAction) updateDB(ctx context.Context) error {
if err != nil {
return fmt.Errorf("invalid node ID UUID: %w", err)
}
beginTime, err := cdb.ParseTimeWithTimezone(d.data.Begin, d.node.Tz)
beginTime, err := time.Parse(time.RFC3339Nano, d.data.Begin)
if err != nil {
return fmt.Errorf("invalid begin time format: %w", err)
}
Expand All @@ -132,8 +132,8 @@ func (d *jobFeedInstanceAction) updateDB(ctx context.Context) error {
}

if d.data.End != "" {
// field End is present, process as action end
endTime, err := cdb.ParseTimeWithTimezone(d.data.End, d.node.Tz)
// field End is present, process as an end action
endTime, err := time.Parse(time.RFC3339Nano, d.data.End)
if err != nil {
return fmt.Errorf("invalid end time format: %w", err)
}
Expand Down
Loading