Exemple #1
0
func getTestHandler() (*runner.Runner, *Controller) {
	r := runner.New("AlogoliaConnector-Test")
	err := r.Init()
	if err != nil {
		panic(err)
	}

	appConfig := config.MustRead(r.Conf.Path)

	algolia := algoliasearch.NewClient(appConfig.Algolia.AppId, appConfig.Algolia.ApiSecretKey)
	// create message handler
	return r, New(r.Log, algolia, ".test")

}
Exemple #2
0
func main() {
	r := runner.New(Name)
	if err := r.Init(); err != nil {
		fmt.Println(err)
		return
	}
	defer r.Close()

	// init mongo connection
	appConfig := config.MustRead(r.Conf.Path)
	modelhelper.Initialize(appConfig.Mongo)
	defer modelhelper.Close()

	algolia := algoliasearch.NewClient(
		appConfig.Algolia.AppId,
		appConfig.Algolia.ApiSecretKey,
	)

	// create message handler
	handler := algoliaconnector.New(r.Log, algolia, appConfig.Algolia.IndexSuffix)
	counter := 0
	for b := 0; ; b++ {
		var accounts []models.Account

		err := (&models.Account{}).Some(&accounts, &bongo.Query{
			Pagination: *bongo.NewPagination(100, b*100),
		})
		if err != nil {
			r.Log.Error(err.Error())
			continue
		}

		for _, account := range accounts {
			counter++
			r.Log.Info("[%d]: currently migrating: '%v'", counter, account.Nick)
			if err := handler.AccountUpdated(&account); err != nil {
				r.Log.Error(err.Error())
				continue
			}
		}

		if len(accounts) < 100 {
			break
		}
	}
}
Exemple #3
0
func main() {
	r := runner.New(Name)
	if err := r.Init(); err != nil {
		log.Fatal(err)
	}

	appConfig := config.MustRead(r.Conf.Path)

	algolia := algoliasearch.NewClient(appConfig.Algolia.AppId, appConfig.Algolia.ApiSecretKey)

	// create message handler
	handler := algoliaconnector.New(r.Log, algolia, appConfig.Algolia.IndexSuffix)

	if err := handler.RemoveGuestAccounts(); err != nil {
		r.Log.Error("Could not remove guest accounts: %s", err)
	}

}
Exemple #4
0
func main() {
	r := runner.New(Name)
	if err := r.Init(); err != nil {
		fmt.Println(err)
		return
	}
	defer r.Close()

	appConfig := config.MustRead(r.Conf.Path)

	algolia := algoliasearch.NewClient(
		appConfig.Algolia.AppId,
		appConfig.Algolia.ApiSecretKey,
	)

	// create message handler
	handler := algoliaconnector.New(r.Log, algolia, appConfig.Algolia.IndexSuffix)
	counter := 0
	for b := 0; ; b++ {
		counter++

		topics, err := (&models.Channel{}).List(&request.Query{
			GroupName: "koding",
			Type:      "topic",
			Limit:     100,
			Skip:      b * 100,
		})
		if err != nil {
			r.Log.Error(err.Error())
			return
		}

		for _, topic := range topics {
			r.Log.Info("[%d] currently migrating: '%v'", counter, topic.Name)
			handler.ChannelCreated(&topic)
		}

		if len(topics) < 100 {
			break
		}
	}
}
Exemple #5
0
func main() {
	r := runner.New(Name)
	if err := r.Init(); err != nil {
		log.Fatal(err)
	}

	appConfig := config.MustRead(r.Conf.Path)

	algolia := algoliasearch.NewClient(appConfig.Algolia.AppId, appConfig.Algolia.ApiSecretKey)
	modelhelper.Initialize(appConfig.Mongo)
	defer modelhelper.Close()

	// create message handler
	handler := algoliaconnector.New(r.Log, algolia, appConfig.Algolia.IndexSuffix)

	index, ok := indexes.(map[string]interface{})
	items, ok := index["items"].([]interface{})
	if !ok {
		return
	}
	for _, item := range items {
		it, ok := item.(map[string]interface{})
		if !ok {
			continue
		}
		updatedAt := it["updatedAt"].(string)
		t, err := time.Parse(time.RFC3339, updatedAt)
		if err != nil {
			fmt.Println("parsing time:", err)
			return
		}

		if t.Before(GetLast60Days()) {
			if _, err := handler.InitAndDeleteIndex(it["name"].(string)); err != nil {
				fmt.Println(err)
				return
			}
		}
	}

	r.Wait()
}
Exemple #6
0
func main() {
	r := runner.New(Name)
	if err := r.Init(); err != nil {
		log.Fatal(err)
	}

	appConfig := config.MustRead(r.Conf.Path)

	algolia := algoliasearch.NewClient(appConfig.Algolia.AppId, appConfig.Algolia.ApiSecretKey)
	modelhelper.Initialize(appConfig.Mongo)
	defer modelhelper.Close()

	// create message handler
	handler := algoliaconnector.New(r.Log, algolia, appConfig.Algolia.IndexSuffix)

	if err := handler.DeleteNicksWithQueryBrowseAll(""); err != nil {
		r.Log.Error("Could not remove guest accounts: %s", err)
	}

	r.Wait()
}
Exemple #7
0
func main() {
	r := runner.New(Name)
	if err := r.Init(); err != nil {
		fmt.Println(err)
		return
	}
	defer r.Close()

	appConfig := config.MustRead(r.Conf.Path)

	algolia := algoliasearch.NewClient(
		appConfig.Algolia.AppId,
		appConfig.Algolia.ApiSecretKey,
	)

	// create message handler
	handler := algoliaconnector.New(r.Log, algolia, appConfig.Algolia.IndexSuffix)

	if err := migrateChannels(r, handler); err != nil {
		panic(err)
	}
}
Exemple #8
0
func main() {
	r := runner.New(Name)
	if err := r.Init(); err != nil {
		log.Fatal(err.Error())
	}

	appConfig := config.MustRead(r.Conf.Path)

	// init mongo connection
	modelhelper.Initialize(appConfig.Mongo)
	defer modelhelper.Close()

	algolia := algoliasearch.NewClient(appConfig.Algolia.AppId, appConfig.Algolia.ApiSecretKey)

	// create message handler
	handler := algoliaconnector.New(r.Log, algolia, appConfig.Algolia.IndexSuffix)
	if err := handler.Init(); err != nil {
		//  this is not a blocker for algoliaconnector worker, we can continue working
		r.Log.Error("Err while init: %s", err.Error())
	}

	r.SetContext(handler)
	r.Register(models.Channel{}).OnCreate().Handle((*algoliaconnector.Controller).ChannelCreated)
	r.Register(models.Channel{}).OnUpdate().Handle((*algoliaconnector.Controller).ChannelUpdated)
	r.Register(models.Account{}).OnCreate().Handle((*algoliaconnector.Controller).AccountCreated)
	r.Register(models.Account{}).OnUpdate().Handle((*algoliaconnector.Controller).AccountUpdated)
	r.Register(models.ChannelMessageList{}).OnCreate().Handle((*algoliaconnector.Controller).MessageListSaved)
	r.Register(models.ChannelMessageList{}).OnDelete().Handle((*algoliaconnector.Controller).MessageListDeleted)
	r.Register(models.ChannelMessage{}).OnUpdate().Handle((*algoliaconnector.Controller).MessageUpdated)

	// participant related events
	r.Register(models.ChannelParticipant{}).OnCreate().Handle((*algoliaconnector.Controller).ParticipantCreated)
	r.Register(models.ChannelParticipant{}).OnUpdate().Handle((*algoliaconnector.Controller).ParticipantUpdated)

	r.Listen()
	r.Wait()
}
Exemple #9
0
func (mwc *Controller) migrateAllAccountsToAlgolia() {
	mwc.log.Notice("Account migration to Algolia started")
	successCount := 0

	s := modelhelper.Selector{
		"type": "registered",
	}

	c := config.MustGet()

	algolia := algoliasearch.NewClient(c.Algolia.AppId, c.Algolia.ApiSecretKey)
	// create message handler
	handler := algoliaconnector.New(mwc.log, algolia, c.Algolia.IndexSuffix)

	migrateAccount := func(account interface{}) error {
		oldAccount := account.(*mongomodels.Account)

		return handler.AccountCreated(&models.Account{
			OldId: oldAccount.Id.Hex(),
			Nick:  oldAccount.Profile.Nickname,
		})
	}

	iterOptions := helpers.NewIterOptions()
	iterOptions.CollectionName = "jAccounts"
	iterOptions.F = migrateAccount
	iterOptions.Filter = s
	iterOptions.Result = &mongomodels.Account{}
	iterOptions.Limit = 10000000
	iterOptions.Skip = 0
	iterOptions.Sort = []string{"-_id"}

	helpers.Iter(modelhelper.Mongo, iterOptions)

	mwc.log.Notice("Account migration completed for %d account with %d errors", successCount, errAccountCount)
}