Skip to content

Commit

Permalink
Updates on time now
Browse files Browse the repository at this point in the history
  • Loading branch information
brotherlogic committed Oct 17, 2020
1 parent d8866ce commit c63d71e
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions recordadder.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,13 @@ func (s *Server) load(ctx context.Context) (*pb.Queue, error) {
return queue, nil
}

func min(t1, t2 time.Duration) time.Duration {
if t1 < t2 {
return t1
}
return t2
}

func (s *Server) runTimedTask() error {
time.Sleep(time.Second * 10)

Expand All @@ -165,11 +172,13 @@ func (s *Server) runTimedTask() error {
return err
}
for s.running {
time.Sleep(time.Unix(queue.LastAdditionDate, 0).Add(time.Hour * 24).Sub(time.Now()))
minTime := min(time.Unix(queue.LastAdditionDate, 0).Add(time.Hour*24).Sub(time.Now()), time.Unix(queue.GetLastDigitalAddition(), 0).Add(time.Hour*24).Sub(time.Now()))
s.Log(fmt.Sprintf("Sleeping for %v", minTime))
time.Sleep(minTime)
ctx, cancel = utils.ManualContext("adder-load", "adder-load", time.Minute, true)
queue, err = s.load(ctx)
cancel()
if err == nil && time.Now().After(time.Unix(queue.LastAdditionDate, 0).Add(time.Hour*24)) {
if err == nil && (time.Now().After(time.Unix(queue.LastAdditionDate, 0).Add(time.Hour*24)) || time.Now().After(time.Unix(queue.GetLastDigitalAddition(), 0).Add(time.Hour*24))) {

done, err := s.Elect()
if err == nil {
Expand Down

0 comments on commit c63d71e

Please sign in to comment.