Unix timestamps not UnixNano

This commit is contained in:
Alex Dadgar 2015-12-21 13:55:26 -08:00
parent 3a400432dc
commit 6bc0737970
3 changed files with 15 additions and 15 deletions

View File

@ -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.UnixNano())
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

View File

@ -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.UnixNano()))
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.UnixNano())
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.Millisecond)
launch3 := same.Add(2 * time.Second)
launch2 := same.Add(2 * time.Second)
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)

View File

@ -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