rcsserver.go 2.0 KB
Newer Older
T
tanggen 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
// Copyright (C) 2020 Finogeeks Co., Ltd
//
// This program is free software: you can redistribute it and/or  modify
// it under the terms of the GNU Affero General Public License, version 3,
// as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

package rcsserver

import (
	"github.com/finogeeks/ligase/common"
	"github.com/finogeeks/ligase/common/basecomponent"
	"github.com/finogeeks/ligase/common/uid"
	"github.com/finogeeks/ligase/rcsserver/api"
	"github.com/finogeeks/ligase/rcsserver/processors"
	"github.com/finogeeks/ligase/rcsserver/rpc"
	"github.com/finogeeks/ligase/skunkworks/log"
	"github.com/finogeeks/ligase/storage/model"
)

func SetupRCSServerComponent(
	base *basecomponent.BaseDendrite, rpcClient *common.RpcClient,
) {
	dbIface, err := common.GetDBInstance("rcsserver", base.Cfg)
	if err != nil {
		log.Panicw("Failed to connect to rcs server db", log.KeysAndValues{"error", err})
	}

	//monitor := mon.GetInstance()
	//counter := monitor.NewLabeledCounter("rcsserver_hit", []string{"target", "repo", "func"})

	db := dbIface.(model.RCSServerDatabase)
	idg, _ := uid.NewDefaultIdGenerator(base.Cfg.Matrix.InstanceId)
	db.SetIDGenerator(idg)
	//db.SetMonitor(counter)
	/*
		repo := new(repos.RCSServerRepo)
		repo.SetPersist(db)
		repo.SetMonitor(counter)
	*/
	proc := processors.NewEventProcessor(base.Cfg, idg, db)
	consumer := rpc.NewEventConsumer(base.Cfg, rpcClient, proc)
	if err := consumer.Start(); err != nil {
		log.Panicw("Failed to start rcs event consumer", log.KeysAndValues{"error", err})
	}

	apiConsumer := api.NewInternalMsgConsumer(*base.Cfg, rpcClient, idg, db)
	apiConsumer.Start()
}