Moved infra/ to internal/ sub-dir
This commit is contained in:
28
src/internal/chronos/cache_permissions_job.go
Normal file
28
src/internal/chronos/cache_permissions_job.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package chronos
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"git.ego.freeddns.org/egommerce/identity-service/internal/infra/repository"
|
||||
"git.ego.freeddns.org/egommerce/identity-service/internal/service"
|
||||
)
|
||||
|
||||
type CachePermissionsJob struct {
|
||||
sch *Chronos
|
||||
}
|
||||
|
||||
func NewCachePermissionsJob(sch *Chronos) CachePermissionsJob {
|
||||
return CachePermissionsJob{sch: sch}
|
||||
}
|
||||
|
||||
func (j CachePermissionsJob) Run() {
|
||||
userRepo := repository.NewUserRepository(j.sch.GetDatabase())
|
||||
roleRepo := repository.NewRoleRepository(j.sch.GetDatabase())
|
||||
urlRepo := repository.NewURLAccessRepository(j.sch.GetDatabase())
|
||||
authSrv := service.NewAuthService(userRepo, j.sch.GetCache())
|
||||
guardSrv := service.NewGuardService(authSrv, j.sch.GetCache(), userRepo, roleRepo, urlRepo)
|
||||
|
||||
guardSrv.CacheAllPermissions()
|
||||
fmt.Println(time.Now().String() + " permission successfully cached")
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"time"
|
||||
|
||||
"git.ego.freeddns.org/egommerce/identity-service/common"
|
||||
"git.ego.freeddns.org/egommerce/identity-service/internal/chronos/jobs"
|
||||
|
||||
"github.com/go-redis/redis/v8"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
@@ -23,10 +22,10 @@ func New(c *common.Config) *Chronos {
|
||||
}
|
||||
|
||||
func (c *Chronos) Start() error {
|
||||
job := jobs.NewCachePermissionsJob()
|
||||
s := clockwerk.New()
|
||||
s.Every(30 * time.Second).Do(job)
|
||||
s.Start()
|
||||
job := NewCachePermissionsJob(c)
|
||||
sch := clockwerk.New()
|
||||
sch.Every(30 * time.Second).Do(job)
|
||||
sch.Start()
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -35,18 +34,18 @@ func (c *Chronos) RegisterHandler(name string, fn func() any) {
|
||||
c.handlers[name] = fn()
|
||||
}
|
||||
|
||||
func (s *Chronos) OnShutdown() {
|
||||
func (c *Chronos) OnShutdown() {
|
||||
log.Println("Chronos is going down...")
|
||||
|
||||
// s.GetDatabase().Close()
|
||||
// c.GetDatabase().Close()
|
||||
}
|
||||
|
||||
// Plugin helper funcitons
|
||||
// Plugin helper funcitons - refactor needed cause funcs are duplcated in server.go
|
||||
// TODO: move functions below to some common place
|
||||
func (s *Chronos) GetCache() *redis.Client {
|
||||
return (s.handlers["cache"]).(*redis.Client)
|
||||
func (c *Chronos) GetCache() *redis.Client {
|
||||
return (c.handlers["cache"]).(*redis.Client)
|
||||
}
|
||||
|
||||
func (s *Chronos) GetDatabase() *pgxpool.Pool {
|
||||
return (s.handlers["database"]).(*pgxpool.Pool)
|
||||
func (c *Chronos) GetDatabase() *pgxpool.Pool {
|
||||
return (c.handlers["database"]).(*pgxpool.Pool)
|
||||
}
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
package jobs
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
type CachePermissionsJob struct{}
|
||||
|
||||
func NewCachePermissionsJob() CachePermissionsJob {
|
||||
return CachePermissionsJob{}
|
||||
}
|
||||
|
||||
func (j CachePermissionsJob) Run() {
|
||||
fmt.Println(time.Now().String() + " Every 30 seconds")
|
||||
}
|
||||
Reference in New Issue
Block a user