Skip to content

Commit

Permalink
add Exists schedule method
Browse files Browse the repository at this point in the history
  • Loading branch information
naueramant committed Feb 3, 2023
1 parent 85d75e4 commit 328b2d9
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var (
type Schedule interface {
Add(ctx context.Context, task *Task, interval time.Duration, firstExecution time.Time) error
Remove(ctx context.Context, kind string, id string) error
Exists(ctx context.Context, kind string, id string) (bool, error)
RunNow(ctx context.Context, kind string, id string) error
On(ctx context.Context, kind string, handler func(ctx context.Context, task *Task)) error
}
Expand Down Expand Up @@ -152,6 +153,22 @@ func (s *ScheduleImpl) Remove(ctx context.Context, kind string, id string) error
}
}

func (s *ScheduleImpl) Exists(ctx context.Context, kind string, id string) (bool, error) {
scheduleKey := s.taskScheduleKey(kind)

exists, err := s.redisClient.ZScore(ctx, scheduleKey, id).Result()

if err == redis.Nil {
return false, nil
}

if err != nil {
return false, err
}

return exists != 0, nil
}

func (s *ScheduleImpl) RunNow(ctx context.Context, kind string, id string) error {
script := redis.NewScript(`
local queueKey = KEYS[1]
Expand Down

0 comments on commit 328b2d9

Please sign in to comment.