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
Commits
6112106b
Verified
Commit
6112106b
authored
1 year ago
by
Volker Schukai
Browse files
Options
Downloads
Patches
Plain Diff
fix: parse duration
#34
parent
1eef22ed
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
errors.go
+1
-0
1 addition, 0 deletions
errors.go
schedule-interval_test.go
+31
-0
31 additions, 0 deletions
schedule-interval_test.go
scheduler.go
+41
-0
41 additions, 0 deletions
scheduler.go
with
73 additions
and
0 deletions
errors.go
+
1
−
0
View file @
6112106b
...
...
@@ -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
+
31
−
0
View file @
6112106b
// Copyright 2023 schukai GmbH
// SPDX-License-Identifier: AGPL-3.0
package
jobqueue
import
(
"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"
)
}
This diff is collapsed.
Click to expand it.
scheduler.go
+
41
−
0
View file @
6112106b
...
...
@@ -68,3 +68,44 @@ func (sp *SchedulerPersistence) UnmarshalJSON(data []byte) error {
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.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment