mirror of
https://github.com/GrassrootsEconomics/cic-dw.git
synced 2024-11-06 01:06:45 +01:00
Mohamed Sohail
6b71657e5b
* refactor: syncer structure - move syncer jobs to internal dir * refactor: queries struct and pkg updates - update cic-go to latest - separate sql queries by logic * ci: add dependabot
43 lines
908 B
Go
43 lines
908 B
Go
package main
|
|
|
|
import (
|
|
"cic-dw/internal/syncer"
|
|
"github.com/hibiken/asynq"
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
func bootstrapScheduler(redis asynq.RedisConnOpt) (*asynq.Scheduler, error) {
|
|
scheduler := asynq.NewScheduler(redis, nil)
|
|
|
|
for k, v := range conf.Syncers {
|
|
task := asynq.NewTask(k, nil)
|
|
|
|
_, err := scheduler.Register(v, task)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
log.Info().Msgf("successfully registered %s syncer", k)
|
|
}
|
|
|
|
return scheduler, nil
|
|
}
|
|
|
|
func bootstrapProcessor(redis asynq.RedisConnOpt) (*asynq.Server, *asynq.ServeMux) {
|
|
processorServer := asynq.NewServer(
|
|
redis,
|
|
asynq.Config{
|
|
Concurrency: 5,
|
|
},
|
|
)
|
|
|
|
syncer := syncer.New(db, redis, cicnetClient, preparedQueries.core)
|
|
|
|
mux := asynq.NewServeMux()
|
|
mux.HandleFunc("token", syncer.TokenSyncer)
|
|
mux.HandleFunc("cache", syncer.CacheSyncer)
|
|
mux.HandleFunc("ussd", syncer.UssdSyncer)
|
|
|
|
return processorServer, mux
|
|
}
|