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
9d6c2e24
Commit
9d6c2e24
authored
9 years ago
by
Alex Dadgar
Browse files
Options
Download
Email Patches
Plain Diff
Always add jobs to periodic tracker
parent
7f2ffe4c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
nomad/fsm.go
+15
-8
nomad/fsm.go
nomad/periodic_test.go
+25
-0
nomad/periodic_test.go
with
40 additions
and
8 deletions
+40
-8
nomad/fsm.go
+
15
-
8
View file @
9d6c2e24
...
...
@@ -208,15 +208,22 @@ func (n *nomadFSM) applyUpsertJob(buf []byte, index uint64) interface{} {
return
err
}
//
If it is periodic, insert it into the periodic runner and record
the
//
time it was inserted.
if
req
.
Job
.
IsPeriodic
()
{
if
err
:=
n
.
periodicDispatcher
.
Add
(
req
.
Job
);
err
!=
nil
{
n
.
logger
.
Printf
(
"[ERR] nomad.fsm: periodicDispatcher.Add failed: %v"
,
err
)
return
err
}
//
We always add the job to the periodic dispatcher because there is
the
//
possibility that the periodic spec was removed and then we should stop
// tracking it.
if
err
:=
n
.
periodicDispatcher
.
Add
(
req
.
Job
);
err
!=
nil
{
n
.
logger
.
Printf
(
"[ERR] nomad.fsm: periodicDispatcher.Add failed: %v"
,
err
)
return
err
}
// Record the insertion time as a launch.
// If it is periodic, record the time it was inserted. This is necessary for
// recovering during leader election. It is possible that from the time it
// is added to when it was suppose to launch, leader election occurs and the
// job was not launched. In this case, we use the insertion time to
// determine if a launch was missed.
if
req
.
Job
.
IsPeriodic
()
{
// Record the insertion time as a launch. We overload the launch table
// such that the first entry is the insertion time.
launch
:=
&
structs
.
PeriodicLaunch
{
ID
:
req
.
Job
.
ID
,
Launch
:
time
.
Now
()}
if
err
:=
n
.
state
.
UpsertPeriodicLaunch
(
index
,
launch
);
err
!=
nil
{
n
.
logger
.
Printf
(
"[ERR] nomad.fsm: UpsertPeriodicLaunch failed: %v"
,
err
)
...
...
This diff is collapsed.
Click to expand it.
nomad/periodic_test.go
+
25
-
0
View file @
9d6c2e24
...
...
@@ -128,6 +128,31 @@ func TestPeriodicDispatch_Add_UpdateJob(t *testing.T) {
}
}
func
TestPeriodicDispatch_Add_RemoveJob
(
t
*
testing
.
T
)
{
t
.
Parallel
()
p
,
_
:=
testPeriodicDispatcher
()
job
:=
mock
.
PeriodicJob
()
if
err
:=
p
.
Add
(
job
);
err
!=
nil
{
t
.
Fatalf
(
"Add failed %v"
,
err
)
}
tracked
:=
p
.
Tracked
()
if
len
(
tracked
)
!=
1
{
t
.
Fatalf
(
"Add didn't track the job: %v"
,
tracked
)
}
// Update the job to be non-periodic and add it again.
job
.
Periodic
=
nil
if
err
:=
p
.
Add
(
job
);
err
!=
nil
{
t
.
Fatalf
(
"Add failed %v"
,
err
)
}
tracked
=
p
.
Tracked
()
if
len
(
tracked
)
!=
0
{
t
.
Fatalf
(
"Add didn't remove: %v"
,
tracked
)
}
}
func
TestPeriodicDispatch_Add_TriggersUpdate
(
t
*
testing
.
T
)
{
t
.
Parallel
()
p
,
m
:=
testPeriodicDispatcher
()
...
...
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