Skip to content

Commit

Permalink
Handle err from gronx NextTickAfter
Browse files Browse the repository at this point in the history
  • Loading branch information
wsan3 committed May 16, 2024
1 parent 2bf0b13 commit 62f84c5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions api/types/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,13 +354,13 @@ func (s *Schedule) SetError(err string) {
//
// When the provided Schedule type is nil, it
// will set nothing and immediately return.
func (s *Schedule) SetNextRun(err int64) {
func (s *Schedule) SetNextRun(nextRun int64) {
// return if Schedule type is nil
if s == nil {
return
}

s.NextRun = &err
s.NextRun = &nextRun
}

// String implements the Stringer interface for the Schedule type.
Expand Down
9 changes: 7 additions & 2 deletions database/types/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (s *Schedule) ToAPI() *api.Schedule {
schedule := new(api.Schedule)

t := time.Now().UTC()
nextTime, _ := gronx.NextTickAfter(s.Entry.String, t, false)
nextTime, err := gronx.NextTickAfter(s.Entry.String, t, false)

schedule.SetID(s.ID.Int64)
schedule.SetRepo(s.Repo.ToAPI())
Expand All @@ -103,7 +103,12 @@ func (s *Schedule) ToAPI() *api.Schedule {
schedule.SetScheduledAt(s.ScheduledAt.Int64)
schedule.SetBranch(s.Branch.String)
schedule.SetError(s.Error.String)
schedule.SetNextRun(nextTime.Unix())

if err != nil {
schedule.SetNextRun(nextTime.Unix())
} else {
schedule.SetNextRun(0)
}

return schedule
}
Expand Down

0 comments on commit 62f84c5

Please sign in to comment.