cic-custodial/cmd/service/tasker.go

83 lines
2.5 KiB
Go
Raw Normal View History

2023-02-02 13:29:43 +01:00
package main
import (
"github.com/grassrootseconomics/cic-custodial/internal/tasker"
"github.com/grassrootseconomics/cic-custodial/internal/tasker/task"
"github.com/grassrootseconomics/cic-custodial/pkg/redis"
"github.com/hibiken/asynq"
)
// Load tasker handlers, injecting any necessary handler dependencies from the system container.
2023-02-02 13:29:43 +01:00
func initTasker(custodialContainer *custodial, redisPool *redis.RedisPool) *tasker.TaskerServer {
lo.Debug("Bootstrapping tasker")
2023-02-09 12:23:37 +01:00
js, err := initJetStream()
if err != nil {
lo.Fatal("filters: critical error loading jetstream", "error", err)
}
2023-02-02 13:29:43 +01:00
taskerServerOpts := tasker.TaskerServerOpts{
Concurrency: ko.MustInt("asynq.worker_count"),
Logg: lo,
2023-02-12 10:50:43 +01:00
LogLevel: asynq.ErrorLevel,
2023-02-02 13:29:43 +01:00
RedisPool: redisPool,
SystemContainer: custodialContainer.systemContainer,
TaskerClient: custodialContainer.taskerClient,
}
if debugFlag {
taskerServerOpts.LogLevel = asynq.DebugLevel
}
taskerServer := tasker.NewTaskerServer(taskerServerOpts)
taskerServer.RegisterHandlers(tasker.PrepareAccountTask, task.PrepareAccount(
custodialContainer.noncestore,
custodialContainer.taskerClient,
2023-02-09 12:23:37 +01:00
js,
2023-02-02 13:29:43 +01:00
))
2023-02-12 10:50:43 +01:00
taskerServer.RegisterHandlers(tasker.RegisterAccountOnChain, task.RegisterAccountOnChainProcessor(
custodialContainer.celoProvider,
custodialContainer.lockProvider,
custodialContainer.noncestore,
custodialContainer.pgStore,
custodialContainer.systemContainer,
custodialContainer.taskerClient,
js,
))
2023-02-02 13:29:43 +01:00
taskerServer.RegisterHandlers(tasker.GiftGasTask, task.GiftGasProcessor(
custodialContainer.celoProvider,
custodialContainer.lockProvider,
2023-02-09 12:23:37 +01:00
custodialContainer.noncestore,
custodialContainer.pgStore,
2023-02-02 13:29:43 +01:00
custodialContainer.systemContainer,
custodialContainer.taskerClient,
2023-02-09 12:23:37 +01:00
js,
2023-02-02 13:29:43 +01:00
))
taskerServer.RegisterHandlers(tasker.GiftTokenTask, task.GiftTokenProcessor(
custodialContainer.celoProvider,
custodialContainer.lockProvider,
2023-02-09 12:23:37 +01:00
custodialContainer.noncestore,
custodialContainer.pgStore,
2023-02-02 13:29:43 +01:00
custodialContainer.systemContainer,
custodialContainer.taskerClient,
2023-02-09 12:23:37 +01:00
js,
2023-02-02 13:29:43 +01:00
))
2023-02-09 12:23:37 +01:00
taskerServer.RegisterHandlers(tasker.SignTransferTask, task.SignTransfer(
2023-02-02 13:29:43 +01:00
custodialContainer.celoProvider,
2023-02-09 12:23:37 +01:00
custodialContainer.keystore,
2023-02-02 13:29:43 +01:00
custodialContainer.lockProvider,
2023-02-09 12:23:37 +01:00
custodialContainer.noncestore,
custodialContainer.pgStore,
2023-02-02 13:29:43 +01:00
custodialContainer.systemContainer,
custodialContainer.taskerClient,
2023-02-09 12:23:37 +01:00
js,
2023-02-02 13:29:43 +01:00
))
taskerServer.RegisterHandlers(tasker.TxDispatchTask, task.TxDispatch(
custodialContainer.celoProvider,
2023-02-09 12:23:37 +01:00
custodialContainer.pgStore,
js,
2023-02-02 13:29:43 +01:00
))
return taskerServer
}