Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Job Queues
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Jira
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Monitor
Service Desk
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OSS
Libraries
Go
Services
Job Queues
Compare revisions
v1.15.0 to v1.15.1
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
oss/libraries/go/services/job-queues
Select target project
No results found
v1.15.1
Select Git revision
Branches
master
Tags
v1.0.0
v1.0.1
v1.1.0
v1.10.0
v1.10.1
v1.10.2
v1.11.0
v1.12.0
v1.12.1
v1.12.2
v1.12.3
v1.12.4
v1.12.5
v1.12.6
v1.12.7
v1.12.8
v1.13.0
v1.13.1
v1.13.2
v1.14.0
v1.15.0
v1.15.1
v1.15.10
v1.15.11
v1.15.12
v1.15.13
v1.15.14
v1.15.15
v1.15.16
v1.15.17
v1.15.2
v1.15.3
v1.15.4
v1.15.5
v1.15.6
v1.15.7
v1.15.8
v1.15.9
v1.16.0
v1.16.1
v1.17.0
v1.18.0
v1.18.1
v1.18.2
v1.19.0
v1.19.1
v1.19.2
v1.19.3
v1.19.4
v1.2.0
v1.20.0
v1.20.1
v1.20.2
v1.20.3
v1.21.0
v1.21.1
v1.22.0
v1.23.0
v1.23.1
v1.23.2
v1.3.0
v1.3.1
v1.3.2
v1.4.0
v1.5.0
v1.5.1
v1.6.0
v1.6.1
v1.7.0
v1.7.1
v1.7.2
v1.7.3
v1.8.0
v1.8.1
v1.9.0
76 results
Swap
Target
oss/libraries/go/services/job-queues
Select target project
oss/libraries/go/services/job-queues
1 result
v1.15.0
Select Git revision
Branches
master
Tags
v1.0.0
v1.0.1
v1.1.0
v1.10.0
v1.10.1
v1.10.2
v1.11.0
v1.12.0
v1.12.1
v1.12.2
v1.12.3
v1.12.4
v1.12.5
v1.12.6
v1.12.7
v1.12.8
v1.13.0
v1.13.1
v1.13.2
v1.14.0
v1.15.0
v1.15.1
v1.15.10
v1.15.11
v1.15.12
v1.15.13
v1.15.14
v1.15.15
v1.15.16
v1.15.17
v1.15.2
v1.15.3
v1.15.4
v1.15.5
v1.15.6
v1.15.7
v1.15.8
v1.15.9
v1.16.0
v1.16.1
v1.17.0
v1.18.0
v1.18.1
v1.18.2
v1.19.0
v1.19.1
v1.19.2
v1.19.3
v1.19.4
v1.2.0
v1.20.0
v1.20.1
v1.20.2
v1.20.3
v1.21.0
v1.21.1
v1.22.0
v1.23.0
v1.23.1
v1.23.2
v1.3.0
v1.3.1
v1.3.2
v1.4.0
v1.5.0
v1.5.1
v1.6.0
v1.6.1
v1.7.0
v1.7.1
v1.7.2
v1.7.3
v1.8.0
v1.8.1
v1.9.0
76 results
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Commits on Source (2)
fix: parse duration
#34
· 6112106b
Volker Schukai
authored
1 year ago
Verified
6112106b
fix: parse duration in json
#35
· a3c67f13
Volker Schukai
authored
1 year ago
Verified
a3c67f13
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
errors.go
+1
-0
1 addition, 0 deletions
errors.go
schedule-interval_test.go
+60
-0
60 additions, 0 deletions
schedule-interval_test.go
scheduler.go
+51
-1
51 additions, 1 deletion
scheduler.go
with
112 additions
and
1 deletion
errors.go
View file @
a3c67f13
...
...
@@ -49,4 +49,5 @@ var (
ErrCannotLoadStatsFromDatabase
=
fmt
.
Errorf
(
"errors while loading stats from database"
)
ErrInvalidTime
=
fmt
.
Errorf
(
"invalid time"
)
ErrSchedulerMisconfiguration
=
fmt
.
Errorf
(
"scheduler misconfiguration"
)
ErrInvalidDuration
=
fmt
.
Errorf
(
"invalid duration"
)
)
This diff is collapsed.
Click to expand it.
schedule-interval_test.go
0 → 100644
View file @
a3c67f13
// Copyright 2023 schukai GmbH
// SPDX-License-Identifier: AGPL-3.0
package
jobqueue
import
(
"encoding/json"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3"
"testing"
"time"
)
// TestUnmarshalYAML tests the unmarshalling of the SchedulerPersistence struct
func
TestUnmarshalYAML
(
t
*
testing
.
T
)
{
yamlStr
:=
`
time: "2023-12-06T15:04:05Z"
interval: "1h30m"
`
sp
:=
SchedulerPersistence
{}
err
:=
yaml
.
Unmarshal
([]
byte
(
yamlStr
),
&
sp
)
assert
.
NoError
(
t
,
err
)
expectedTime
,
_
:=
time
.
Parse
(
time
.
RFC3339
,
"2023-12-06T15:04:05Z"
)
assert
.
Equal
(
t
,
expectedTime
,
*
sp
.
Time
,
"the time should be parsed correctly"
)
expectedInterval
,
_
:=
time
.
ParseDuration
(
"1h30m"
)
assert
.
Equal
(
t
,
expectedInterval
,
sp
.
Delay
,
"the interval should be parsed correctly"
)
}
// TestUnmarshalJSON tests the UnmarshalJSON method
func
TestUnmarshalJSON
(
t
*
testing
.
T
)
{
// Example JSON string representing SchedulerPersistence
jsonStr
:=
`{
"time": "2023-12-06T15:04:05Z",
"interval": "1h30m"
}`
// Create an instance of SchedulerPersistence
sp
:=
SchedulerPersistence
{}
// Unmarshal the JSON string into the sp structure
err
:=
json
.
Unmarshal
([]
byte
(
jsonStr
),
&
sp
)
assert
.
NoError
(
t
,
err
,
"Unmarshalling should not produce an error"
)
// Verify that the Time field is correctly parsed
expectedTime
,
_
:=
time
.
Parse
(
time
.
RFC3339
,
"2023-12-06T15:04:05Z"
)
if
sp
.
Time
!=
nil
{
assert
.
Equal
(
t
,
expectedTime
,
*
sp
.
Time
,
"Time should be correctly parsed"
)
}
else
{
t
.
Error
(
"Time field is nil, but it should not be"
)
}
// Verify that the Delay field is correctly parsed
expectedInterval
,
_
:=
time
.
ParseDuration
(
"1h30m"
)
assert
.
Equal
(
t
,
expectedInterval
,
sp
.
Delay
,
"Interval should be correctly parsed"
)
}
This diff is collapsed.
Click to expand it.
scheduler.go
View file @
a3c67f13
...
...
@@ -41,7 +41,8 @@ func (sp *SchedulerPersistence) UnmarshalJSON(data []byte) error {
// Anonymous structure to avoid endless recursion
type
Alias
SchedulerPersistence
aux
:=
&
struct
{
Time
*
string
`json:"time,omitempty"`
Time
*
string
`json:"time,omitempty"`
Interval
*
string
`json:"interval,omitempty"`
// Ensure this matches the JSON field name
*
Alias
}{
Alias
:
(
*
Alias
)(
sp
),
...
...
@@ -66,5 +67,54 @@ func (sp *SchedulerPersistence) UnmarshalJSON(data []byte) error {
sp
.
Time
=
&
t
}
if
aux
.
Interval
!=
nil
{
d
,
err
:=
time
.
ParseDuration
(
*
aux
.
Interval
)
if
err
!=
nil
{
return
err
}
sp
.
Delay
=
d
}
return
nil
}
func
(
sp
*
SchedulerPersistence
)
UnmarshalYAML
(
unmarshal
func
(
interface
{})
error
)
error
{
// Anonymous structure to avoid endless recursion
type
Alias
SchedulerPersistence
aux
:=
&
struct
{
Time
*
string
`yaml:"time,omitempty"`
Interval
*
string
`yaml:"interval,omitempty"`
*
Alias
}{
Alias
:
(
*
Alias
)(
sp
),
}
if
err
:=
unmarshal
(
&
aux
);
err
!=
nil
{
return
err
}
if
aux
.
Time
!=
nil
{
var
t
time
.
Time
var
err
error
for
_
,
format
:=
range
SupportedTimeFormats
{
t
,
err
=
time
.
Parse
(
format
,
*
aux
.
Time
)
if
err
==
nil
{
break
}
}
if
err
!=
nil
{
return
err
}
sp
.
Time
=
&
t
}
if
aux
.
Interval
!=
nil
{
d
,
err
:=
time
.
ParseDuration
(
*
aux
.
Interval
)
if
err
!=
nil
{
return
err
}
sp
.
Delay
=
d
}
return
nil
}
This diff is collapsed.
Click to expand it.