Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Nomad
Commits
15623e52
Commit
15623e52
authored
7 years ago
by
Alex Dadgar
Browse files
Options
Download
Email Patches
Plain Diff
Fix command line
parent
67df44cd
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
api/jobs.go
+4
-3
api/jobs.go
command/job_run.go
+7
-3
command/job_run.go
command/job_status.go
+6
-4
command/job_status.go
nomad/structs/structs.go
+3
-3
nomad/structs/structs.go
with
20 additions
and
13 deletions
+20
-13
api/jobs.go
+
4
-
3
View file @
15623e52
...
...
@@ -9,6 +9,7 @@ import (
"github.com/gorhill/cronexpr"
"github.com/hashicorp/nomad/helper"
"github.com/hashicorp/nomad/nomad/structs"
)
const
(
...
...
@@ -537,14 +538,14 @@ func (p *PeriodicConfig) Canonicalize() {
// passed time. If no matching instance exists, the zero value of time.Time is
// returned. The `time.Location` of the returned value matches that of the
// passed time.
func
(
p
*
PeriodicConfig
)
Next
(
fromTime
time
.
Time
)
time
.
Time
{
func
(
p
*
PeriodicConfig
)
Next
(
fromTime
time
.
Time
)
(
time
.
Time
,
error
)
{
if
*
p
.
SpecType
==
PeriodicSpecCron
{
if
e
,
err
:=
cronexpr
.
Parse
(
*
p
.
Spec
);
err
==
nil
{
return
e
.
Next
(
fromTime
)
return
structs
.
CronPars
eNext
(
e
,
fromTime
,
*
p
.
Spec
)
}
}
return
time
.
Time
{}
return
time
.
Time
{}
,
nil
}
func
(
p
*
PeriodicConfig
)
GetLocation
()
(
*
time
.
Location
,
error
)
{
...
...
This diff is collapsed.
Click to expand it.
command/job_run.go
+
7
-
3
View file @
15623e52
...
...
@@ -247,9 +247,13 @@ func (c *JobRunCommand) Run(args []string) int {
loc
,
err
:=
job
.
Periodic
.
GetLocation
()
if
err
==
nil
{
now
:=
time
.
Now
()
.
In
(
loc
)
next
:=
job
.
Periodic
.
Next
(
now
)
c
.
Ui
.
Output
(
fmt
.
Sprintf
(
"Approximate next launch time: %s (%s from now)"
,
formatTime
(
next
),
formatTimeDifference
(
now
,
next
,
time
.
Second
)))
next
,
err
:=
job
.
Periodic
.
Next
(
now
)
if
err
!=
nil
{
c
.
Ui
.
Error
(
fmt
.
Sprintf
(
"Error determining next launch time: %v"
,
err
))
}
else
{
c
.
Ui
.
Output
(
fmt
.
Sprintf
(
"Approximate next launch time: %s (%s from now)"
,
formatTime
(
next
),
formatTimeDifference
(
now
,
next
,
time
.
Second
)))
}
}
}
else
if
!
paramjob
{
c
.
Ui
.
Output
(
"Evaluation ID: "
+
evalID
)
...
...
This diff is collapsed.
Click to expand it.
command/job_status.go
+
6
-
4
View file @
15623e52
...
...
@@ -185,10 +185,12 @@ func (c *JobStatusCommand) Run(args []string) int {
location
,
err
:=
job
.
Periodic
.
GetLocation
()
if
err
==
nil
{
now
:=
time
.
Now
()
.
In
(
location
)
next
:=
job
.
Periodic
.
Next
(
now
)
basic
=
append
(
basic
,
fmt
.
Sprintf
(
"Next Periodic Launch|%s"
,
fmt
.
Sprintf
(
"%s (%s from now)"
,
formatTime
(
next
),
formatTimeDifference
(
now
,
next
,
time
.
Second
))))
next
,
err
:=
job
.
Periodic
.
Next
(
now
)
if
err
==
nil
{
basic
=
append
(
basic
,
fmt
.
Sprintf
(
"Next Periodic Launch|%s"
,
fmt
.
Sprintf
(
"%s (%s from now)"
,
formatTime
(
next
),
formatTimeDifference
(
now
,
next
,
time
.
Second
))))
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
nomad/structs/structs.go
+
3
-
3
View file @
15623e52
...
...
@@ -2657,9 +2657,9 @@ func (p *PeriodicConfig) Canonicalize() {
p
.
location
=
l
}
//
c
ronParseNext is a helper that parses the next time for the given expression
//
C
ronParseNext is a helper that parses the next time for the given expression
// but captures any panic that may occur in the underlying library.
func
c
ronParseNext
(
e
*
cronexpr
.
Expression
,
fromTime
time
.
Time
,
spec
string
)
(
t
time
.
Time
,
err
error
)
{
func
C
ronParseNext
(
e
*
cronexpr
.
Expression
,
fromTime
time
.
Time
,
spec
string
)
(
t
time
.
Time
,
err
error
)
{
defer
func
()
{
if
recover
()
!=
nil
{
t
=
time
.
Time
{}
...
...
@@ -2678,7 +2678,7 @@ func (p *PeriodicConfig) Next(fromTime time.Time) (time.Time, error) {
switch
p
.
SpecType
{
case
PeriodicSpecCron
:
if
e
,
err
:=
cronexpr
.
Parse
(
p
.
Spec
);
err
==
nil
{
return
c
ronParseNext
(
e
,
fromTime
,
p
.
Spec
)
return
C
ronParseNext
(
e
,
fromTime
,
p
.
Spec
)
}
case
PeriodicSpecTest
:
split
:=
strings
.
Split
(
p
.
Spec
,
","
)
...
...
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
Menu
Projects
Groups
Snippets
Help