2025-01-19 06:02:07 -06:00
|
|
|
package job
|
|
|
|
|
|
|
|
|
|
import (
|
2025-04-06 06:04:08 -07:00
|
|
|
"context"
|
2025-05-29 08:15:35 -07:00
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/go-co-op/gocron/v2"
|
2025-01-19 06:02:07 -06:00
|
|
|
|
2025-02-05 18:08:01 +01:00
|
|
|
"github.com/pocket-id/pocket-id/backend/internal/service"
|
2025-01-19 06:02:07 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type LdapJobs struct {
|
|
|
|
|
ldapService *service.LdapService
|
|
|
|
|
appConfigService *service.AppConfigService
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-28 18:13:50 +09:00
|
|
|
func (s *Scheduler) RegisterLdapJobs(ctx context.Context, ldapService *service.LdapService, appConfigService *service.AppConfigService) error {
|
2025-01-19 06:02:07 -06:00
|
|
|
jobs := &LdapJobs{ldapService: ldapService, appConfigService: appConfigService}
|
|
|
|
|
|
2025-04-28 18:13:50 +09:00
|
|
|
// Register the job to run every hour
|
2025-05-29 08:15:35 -07:00
|
|
|
return s.registerJob(ctx, "SyncLdap", gocron.DurationJob(time.Hour), jobs.syncLdap, true)
|
2025-01-19 06:02:07 -06:00
|
|
|
}
|
|
|
|
|
|
2025-04-06 06:04:08 -07:00
|
|
|
func (j *LdapJobs) syncLdap(ctx context.Context) error {
|
2025-04-10 04:41:22 -07:00
|
|
|
if !j.appConfigService.GetDbConfig().LdapEnabled.IsTrue() {
|
2025-04-06 06:04:08 -07:00
|
|
|
return nil
|
2025-01-19 06:02:07 -06:00
|
|
|
}
|
2025-04-06 06:04:08 -07:00
|
|
|
|
|
|
|
|
return j.ldapService.SyncAll(ctx)
|
2025-01-19 06:02:07 -06:00
|
|
|
}
|