Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Nomad
Commits
60cffa81
Commit
60cffa81
authored
9 years ago
by
Alex Dadgar
Browse files
Options
Download
Email Patches
Plain Diff
Unix timestamps not UnixNano
parent
9d6c2e24
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
nomad/periodic.go
+2
-2
nomad/periodic.go
nomad/periodic_test.go
+11
-11
nomad/periodic_test.go
nomad/structs/structs.go
+2
-2
nomad/structs/structs.go
with
15 additions
and
15 deletions
+15
-15
nomad/periodic.go
+
2
-
2
View file @
60cffa81
...
...
@@ -398,7 +398,7 @@ func (p *PeriodicDispatch) deriveJob(periodicJob *structs.Job, time time.Time) (
// deriveJobID returns a job ID based on the parent periodic job and the launch
// time.
func
(
p
*
PeriodicDispatch
)
derivedJobID
(
periodicJob
*
structs
.
Job
,
time
time
.
Time
)
string
{
return
fmt
.
Sprintf
(
"%s%s%d"
,
periodicJob
.
ID
,
JobLaunchSuffix
,
time
.
Unix
Nano
())
return
fmt
.
Sprintf
(
"%s%s%d"
,
periodicJob
.
ID
,
JobLaunchSuffix
,
time
.
Unix
())
}
// LaunchTime returns the launch time of the job. This is only valid for
...
...
@@ -414,7 +414,7 @@ func (p *PeriodicDispatch) LaunchTime(jobID string) (time.Time, error) {
return
time
.
Time
{},
fmt
.
Errorf
(
"couldn't parse launch time from eval: %v"
,
jobID
)
}
return
time
.
Unix
(
0
,
int64
(
launch
)),
nil
return
time
.
Unix
(
int64
(
launch
)
,
0
),
nil
}
// Flush clears the state of the PeriodicDispatcher
...
...
This diff is collapsed.
Click to expand it.
nomad/periodic_test.go
+
11
-
11
View file @
60cffa81
...
...
@@ -78,7 +78,7 @@ func testPeriodicJob(times ...time.Time) *structs.Job {
l
:=
make
([]
string
,
len
(
times
))
for
i
,
t
:=
range
times
{
l
[
i
]
=
strconv
.
Itoa
(
int
(
t
.
Unix
Nano
()))
l
[
i
]
=
strconv
.
Itoa
(
int
(
t
.
Round
(
1
*
time
.
Second
)
.
Unix
()))
}
job
.
Periodic
.
Spec
=
strings
.
Join
(
l
,
","
)
...
...
@@ -166,8 +166,8 @@ func TestPeriodicDispatch_Add_TriggersUpdate(t *testing.T) {
}
// Update it to be sooner and re-add.
expected
:=
time
.
Now
()
.
Add
(
1
*
time
.
Second
)
job
.
Periodic
.
Spec
=
fmt
.
Sprintf
(
"%d"
,
expected
.
Unix
Nano
())
expected
:=
time
.
Now
()
.
Round
(
1
*
time
.
Second
)
.
Add
(
1
*
time
.
Second
)
job
.
Periodic
.
Spec
=
fmt
.
Sprintf
(
"%d"
,
expected
.
Unix
())
if
err
:=
p
.
Add
(
job
);
err
!=
nil
{
t
.
Fatalf
(
"Add failed %v"
,
err
)
}
...
...
@@ -293,8 +293,8 @@ func TestPeriodicDispatch_Run_Multiple(t *testing.T) {
p
,
m
:=
testPeriodicDispatcher
()
// Create a job that will be launched twice.
launch1
:=
time
.
Now
()
.
Add
(
1
*
time
.
Second
)
launch2
:=
time
.
Now
()
.
Add
(
2
*
time
.
Second
)
launch1
:=
time
.
Now
()
.
Round
(
1
*
time
.
Second
)
.
Add
(
1
*
time
.
Second
)
launch2
:=
time
.
Now
()
.
Round
(
1
*
time
.
Second
)
.
Add
(
2
*
time
.
Second
)
job
:=
testPeriodicJob
(
launch1
,
launch2
)
// Add it.
...
...
@@ -325,7 +325,7 @@ func TestPeriodicDispatch_Run_SameTime(t *testing.T) {
p
,
m
:=
testPeriodicDispatcher
()
// Create two job that will be launched at the same time.
launch
:=
time
.
Now
()
.
Add
(
1
*
time
.
Second
)
launch
:=
time
.
Now
()
.
Round
(
1
*
time
.
Second
)
.
Add
(
1
*
time
.
Second
)
job
:=
testPeriodicJob
(
launch
)
job2
:=
testPeriodicJob
(
launch
)
...
...
@@ -362,11 +362,11 @@ func TestPeriodicDispatch_Complex(t *testing.T) {
p
,
m
:=
testPeriodicDispatcher
()
// Create some jobs launching at different times.
now
:=
time
.
Now
()
now
:=
time
.
Now
()
.
Round
(
1
*
time
.
Second
)
same
:=
now
.
Add
(
1
*
time
.
Second
)
launch1
:=
same
.
Add
(
1
*
time
.
Second
)
launch2
:=
same
.
Add
(
1500
*
time
.
Millis
econd
)
launch3
:=
same
.
Add
(
2
*
time
.
Second
)
launch2
:=
same
.
Add
(
2
*
time
.
S
econd
)
launch3
:=
same
.
Add
(
3
*
time
.
Second
)
invalid
:=
now
.
Add
(
-
200
*
time
.
Second
)
// Create two jobs launching at the same time.
...
...
@@ -417,7 +417,7 @@ func TestPeriodicDispatch_Complex(t *testing.T) {
}
}
time
.
Sleep
(
4
*
time
.
Second
)
time
.
Sleep
(
5
*
time
.
Second
)
actual
:=
make
(
map
[
string
][]
time
.
Time
,
len
(
expected
))
for
_
,
job
:=
range
jobs
{
launches
,
err
:=
m
.
LaunchTimes
(
p
,
job
.
ID
)
...
...
@@ -439,7 +439,7 @@ func TestPeriodicDispatch_NextLaunch(t *testing.T) {
// Create two job that will be launched at the same time.
invalid
:=
time
.
Unix
(
0
,
0
)
expected
:=
time
.
Now
()
.
Add
(
1
*
time
.
Second
)
expected
:=
time
.
Now
()
.
Round
(
1
*
time
.
Second
)
.
Add
(
1
*
time
.
Second
)
job
:=
testPeriodicJob
(
invalid
)
job2
:=
testPeriodicJob
(
expected
)
...
...
This diff is collapsed.
Click to expand it.
nomad/structs/structs.go
+
2
-
2
View file @
60cffa81
...
...
@@ -938,7 +938,7 @@ const (
PeriodicSpecCron
=
"cron"
// PeriodicSpecTest is only used by unit tests. It is a sorted, comma
// seperated list of unix
nanosecond
timestamps at which to launch.
// seperated list of unix timestamps at which to launch.
PeriodicSpecTest
=
"_internal_test"
)
...
...
@@ -1003,7 +1003,7 @@ func (p *PeriodicConfig) Next(fromTime time.Time) time.Time {
return
time
.
Time
{}
}
times
[
i
]
=
time
.
Unix
(
0
,
int64
(
unix
))
times
[
i
]
=
time
.
Unix
(
int64
(
unix
)
,
0
)
}
// Find the next match
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment