1
0
mirror of https://github.com/pocket-id/pocket-id.git synced 2026-02-16 14:43:39 +00:00

feat: add daily heartbeat request for counting Pocket ID instances (#578)

This commit is contained in:
Elias Schneider
2025-05-28 11:19:45 +02:00
committed by GitHub
parent d29fca155e
commit e0ec607198
14 changed files with 123 additions and 47 deletions

View File

@@ -43,10 +43,8 @@ func (s *Scheduler) Run(ctx context.Context) error {
return nil
}
func (s *Scheduler) registerJob(ctx context.Context, name string, interval string, job func(ctx context.Context) error) error {
_, err := s.scheduler.NewJob(
gocron.CronJob(interval, false),
gocron.NewTask(job),
func (s *Scheduler) registerJob(ctx context.Context, name string, interval string, job func(ctx context.Context) error, runImmediately bool) error {
jobOptions := []gocron.JobOption{
gocron.WithContext(ctx),
gocron.WithEventListeners(
gocron.AfterJobRuns(func(jobID uuid.UUID, jobName string) {
@@ -56,6 +54,16 @@ func (s *Scheduler) registerJob(ctx context.Context, name string, interval strin
log.Printf("Job %q failed with error: %v", name, err)
}),
),
}
if runImmediately {
jobOptions = append(jobOptions, gocron.JobOption(gocron.WithStartImmediately()))
}
_, err := s.scheduler.NewJob(
gocron.CronJob(interval, false),
gocron.NewTask(job),
jobOptions...,
)
if err != nil {