feat: add GetJobsByPrefix, GetJobByName, GetJobByID

This commit is contained in:
Derrick Hammer 2024-02-25 01:58:26 -05:00
parent f47552bf60
commit fc40563ae4
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 41 additions and 1 deletions

View File

@ -3,10 +3,12 @@ package cron
import ( import (
"context" "context"
"errors" "errors"
"strings"
"time"
"github.com/google/uuid" "github.com/google/uuid"
"go.uber.org/fx" "go.uber.org/fx"
"go.uber.org/zap" "go.uber.org/zap"
"time"
"github.com/go-co-op/gocron/v2" "github.com/go-co-op/gocron/v2"
) )
@ -166,3 +168,41 @@ func (c *CronServiceDefault) RerunJob(job CronJob) (gocron.Job, error) {
return ret, nil return ret, nil
} }
func (c *CronServiceDefault) GetJobsByPrefix(prefix string) []gocron.Job {
jobs := c.Scheduler().Jobs()
var ret []gocron.Job
for _, job := range jobs {
if strings.HasPrefix(job.Name(), prefix) {
ret = append(ret, job)
}
}
return ret
}
func (c *CronServiceDefault) GetJobByName(name string) gocron.Job {
jobs := c.Scheduler().Jobs()
for _, job := range jobs {
if job.Name() == name {
return job
}
}
return nil
}
func (c *CronServiceDefault) GetJobByID(id uuid.UUID) gocron.Job {
jobs := c.Scheduler().Jobs()
for _, job := range jobs {
if job.ID() == id {
return job
}
}
return nil
}