Ejemplo n.º 1
0
func main() {
	r := runner.New(Name)
	if err := r.Init(); err != nil {
		log.Fatal(err)
	}

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

	segmentExporter := eventexporter.NewSegmentIOExporter(appConfig.Segment, QueueLength)
	datadogExporter := eventexporter.NewDatadogExporter(r.DogStatsD)

	// TODO
	// we are gonna add this line into the multiexporter
	// firstly, we need to make sure our json data satisfy druid's data specs
	// druidExporter := eventexporter.NewDruidExporter(appConfig.DruidHost)
	// exporter := eventexporter.NewMultiExporter(segmentExporter, datadogExporter, druidExporter)

	exporter := eventexporter.NewMultiExporter(segmentExporter, datadogExporter)

	constructor := emailsender.New(exporter, r.Log, appConfig)
	r.ShutdownHandler = constructor.Close

	r.SetContext(constructor)

	r.Register(emailsender.Mail{}).On(emailsender.SendEmailEventName).Handle((*emailsender.Controller).Process)

	r.Listen()
	r.Wait()
}
Ejemplo n.º 2
0
func main() {
	r := runner.New(Name)
	if err := r.Init(); err != nil {
		fmt.Println(err)
		return
	}

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

	r.SetContext(realtime.New(r.Bongo.Broker.MQ, r.Log))
	r.Register(models.ChannelMessage{}).OnUpdate().Handle((*realtime.Controller).MessageUpdated)
	r.Register(models.MessageReply{}).OnCreate().Handle((*realtime.Controller).MessageReplySaved)
	r.Register(models.MessageReply{}).OnDelete().Handle((*realtime.Controller).MessageReplyDeleted)
	r.Register(models.ChannelMessageList{}).OnCreate().Handle((*realtime.Controller).MessageListSaved)
	r.Register(models.ChannelMessageList{}).OnUpdate().Handle((*realtime.Controller).ChannelMessageListUpdated)
	r.Register(models.ChannelMessageList{}).OnDelete().Handle((*realtime.Controller).MessageListDeleted)
	r.Register(models.ParticipantEvent{}).On(models.ChannelParticipant_Removed_From_Channel_Event).Handle((*realtime.Controller).ChannelParticipantRemoved)
	r.Register(models.ParticipantEvent{}).On(models.ChannelParticipant_Added_To_Channel_Event).Handle((*realtime.Controller).ChannelParticipantsAdded)
	r.Register(models.ChannelParticipant{}).OnUpdate().Handle((*realtime.Controller).ChannelParticipantUpdatedEvent)
	r.Register(models.Channel{}).OnDelete().Handle((*realtime.Controller).ChannelDeletedEvent)
	r.Register(models.Channel{}).OnUpdate().Handle((*realtime.Controller).ChannelUpdatedEvent)
	r.Listen()
	r.Wait()
}
Ejemplo n.º 3
0
func TestChannelPrepareName(t *testing.T) {
	r := runner.New("test")
	if err := r.Init(); err != nil {
		t.Fatalf("couldnt start bongo %s", err.Error())
	}
	defer r.Close()

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

	Convey("While creating PubNub channels", t, func() {
		Convey("Notification channel name format must be as 'notification'-[env]-[nickname]", func() {
			a := &models.Account{}
			a.Nick = "hello"
			nc := NewNotificationChannel(a)
			name := nc.PrepareName()
			expectedName := fmt.Sprintf("notification-%s-%s", appConfig.Environment, a.Nick)
			So(name, ShouldEqual, expectedName)
		})
		Convey("Message update and channel name format must be as 'channel'-[token]", func() {
			c := Channel{}
			c.Token = "12345"
			pc := NewPrivateMessageChannel(c)
			expectedName := fmt.Sprintf("channel-%s", c.Token)
			So(pc.PrepareName(), ShouldEqual, expectedName)

			uim := UpdateInstanceMessage{}
			uim.ChannelToken = "12345"

			um := NewMessageUpdateChannel(uim)
			So(um.PrepareName(), ShouldEqual, expectedName)
		})
	})
}
Ejemplo n.º 4
0
func TestNew(t *testing.T) {
	r := startRunner()
	defer r.Close()

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

	Convey("Given an exporter client", t, func() {
		Convey("Then it should call it", func() {
			mail := &Mail{
				To:         "*****@*****.**",
				Subject:    "Test message",
				Text:       "Example",
				From:       "*****@*****.**",
				Properties: &Properties{Username: "******"},
			}

			exporter := eventexporter.NewFakeExporter()
			c := New(exporter, r.Log, appConfig)

			err := c.Process(mail)
			So(err, ShouldBeNil)

			So(len(exporter.Events), ShouldEqual, 1)
		})
	})
}
Ejemplo n.º 5
0
func main() {
	r := runner.New(Name)
	if err := r.Init(); err != nil {
		fmt.Println(err)
		return
	}

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

	// create a realtime service provider instance.
	pubnub := models.NewPubNub(appConfig.GateKeeper.Pubnub, r.Log)
	defer pubnub.Close()

	mc := mux.NewConfig(Name, appConfig.GateKeeper.Host, appConfig.GateKeeper.Port)
	m := mux.New(mc, r.Log, r.Metrics)

	h := api.NewHandler(pubnub, appConfig, r.Log)

	h.AddHandlers(m)

	// consume messages from RMQ
	// Gatekeeper is not using RMQ, but runner is creating a message queue for
	// each worker.  We need to discard the messages in the queue, otherwise
	// all the messages are piled up
	go r.Listen()

	m.Listen()
	defer m.Close()

	r.Wait()
}
Ejemplo n.º 6
0
func withTestServer(t *testing.T, f func(url string)) {
	const workerName = "pingtest"

	r := runner.New(workerName)
	if err := r.Init(); err != nil {
		t.Fatal(err)
	}

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

	port := tests.GetFreePort()
	mc := mux.NewConfig(workerName, "localhost", port)
	mc.Debug = r.Conf.Debug
	m := mux.New(mc, r.Log, r.Metrics)

	AddHandlers(m)

	m.Listen()

	go r.Listen()

	f(fmt.Sprintf("http://localhost:%s", port))

	if err := r.Close(); err != nil {
		t.Fatalf("server close errored: %s", err.Error())
	}

	// shutdown server
	m.Close()
}
Ejemplo n.º 7
0
func main() {
	r := runner.New(Name)
	if err := r.Init(); err != nil {
		log.Fatal(err)
	}

	if r.Kite == nil {
		r.Log.Fatal("couldnt init kite")
	}

	// remove QOS, we want to consume all the messages from RMQ
	if err := r.Bongo.Broker.Sub.(*broker.Consumer).Consumer.QOS(0); err != nil {
		r.Log.Fatal("couldnt remove the QOS %# v", err)
	}

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

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

	// init with defaults & ensure expireAt index
	mongoCache := cache.NewMongoCacheWithTTL(modelhelper.Mongo.Session, cache.StartGC(), cache.MustEnsureIndexExpireAt())
	defer mongoCache.StopGC()

	handler := collaboration.New(r.Log, mongoCache, appConfig, r.Kite)
	r.SetContext(handler)
	// only listen and operate on collaboration ping messages that are fired by the handler
	r.Register(models.Ping{}).On(collaboration.FireEventName).Handle((*collaboration.Controller).Ping)
	r.Listen()
	r.Wait()
}
Ejemplo n.º 8
0
func TestGetIdsFromMailboxHash(t *testing.T) {
	r := runner.New("test")
	if err := r.Init(); err != nil {
		t.Fatalf("couldnt start bongo %s", err.Error())
	}
	defer r.Close()

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

	Convey("while getting ids from mailboxhash", t, func() {

		Convey("returns error if 1.index of mailboxhash doesn't exist", func() {
			m := &Mail{
				MailboxHash: "message.",
			}

			gid, err := m.getIdsFromMailboxHash()
			So(err, ShouldNotBeNil)
			So(gid, ShouldEqual, 0)
		})

		Convey("returns error if 1.index doesn't exist", func() {
			m := &Mail{
				MailboxHash: "message.1234",
			}

			gid, err := m.getIdsFromMailboxHash()
			So(err, ShouldBeNil)
			So(gid, ShouldEqual, 1234)
		})
	})
}
Ejemplo n.º 9
0
func main() {
	r := runner.New(Name)
	if err := r.Init(); err != nil {
		fmt.Println(err)
		return
	}

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

	// create a realtime service provider instance.
	pubnub := models.NewPubNub(appConfig.GateKeeper.Pubnub, r.Log)
	defer pubnub.Close()

	// When we use the same RMQ connection for both, we received
	// 'Exception (504) Reason: "CHANNEL_ERROR - unexpected method in connection state running"'
	// error at some point. It needs debugging.
	rmqBroker, err := runner.NewRabbitMQ(r.Conf, r.Log).Connect()
	if err != nil {
		fmt.Println(err)
		return
	}
	defer rmqBroker.Conn().Close()

	broker := models.NewBroker(rmqBroker, r.Log)

	r.SetContext(dispatcher.NewController(r.Bongo.Broker.MQ, pubnub, broker))
	r.ListenFor("dispatcher_channel_updated", (*dispatcher.Controller).UpdateChannel)
	r.ListenFor("dispatcher_message_updated", (*dispatcher.Controller).UpdateMessage)
	r.ListenFor("dispatcher_notify_user", (*dispatcher.Controller).NotifyUser)
	r.ListenFor("dispatcher_notify_group", (*dispatcher.Controller).NotifyGroup)
	r.ListenFor("event.channel_participant_removed_from_channel", (*dispatcher.Controller).RevokeChannelAccess)
	r.Listen()

	r.Wait()
}
Ejemplo n.º 10
0
func TestValidate(t *testing.T) {
	r := runner.New("test")
	if err := r.Init(); err != nil {
		t.Fatalf("couldnt start bongo %s", err.Error())
	}
	defer r.Close()

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

	Convey("while testing Validate", t, func() {
		Convey("From field of Mail struct should not be empty, otherwise return err", func() {
			m := &Mail{}
			err := m.Validate()
			So(err, ShouldNotBeNil)
			So(err, ShouldEqual, ErrFromFieldIsNotSet)
		})

		Convey("TextBody field of Mail struct should not be empty, otherwise return err", func() {
			m := &Mail{From: "*****@*****.**"}
			err := m.Validate()
			So(err, ShouldNotBeNil)
			So(err, ShouldEqual, ErrTextBodyIsNotSet)
		})

		Convey("returns nil if Mail struct is set ", func() {
			m := &Mail{From: "*****@*****.**", TextBody: "Some text parapraph"}
			So(m.Validate(), ShouldBeNil)
		})
	})
}
Ejemplo n.º 11
0
func TestIndexSettingsDefaults(t *testing.T) {
	runner, handler := getTestHandler()
	defer runner.Close()

	appConfig := config.MustRead(runner.Conf.Path)
	modelhelper.Initialize(appConfig.Mongo)
	defer modelhelper.Close()

	Convey("given some handler", t, func() {
		err := handler.Init()
		So(err, ShouldBeNil)

		Convey("account email should not be retrievable", func() {
			indexSet, err := handler.indexes.Get(IndexAccounts)
			So(err, ShouldBeNil)

			settings, err := indexSet.Index.GetSettings()
			So(err, ShouldBeNil)

			found := false
			for _, item := range settings.UnretrievableAttributes {
				if item == "email" {
					found = true
				}

			}

			So(found, ShouldBeTrue)
		})
	})
}
Ejemplo n.º 12
0
func TestAccountParticipantAdded(t *testing.T) {
	runner, handler := getTestHandler()
	defer runner.Close()

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

	Convey("given some account", t, func() {
		acc, err := models.CreateAccountInBothDbs()
		So(err, ShouldBeNil)
		So(acc, ShouldNotBeNil)

		tc1 := models.CreateTypedGroupedChannelWithTest(
			acc.Id,
			models.Channel_TYPE_TOPIC,
			models.Channel_KODING_NAME,
		)

		models.AddParticipantsWithTest(tc1.Id, acc.Id)

		cp := &models.ChannelParticipant{
			ChannelId:      tc1.Id,
			AccountId:      acc.Id,
			StatusConstant: models.ChannelParticipant_STATUS_ACTIVE,
		}

		Convey("when the account is already on algolia", func() {
			err := handler.AccountCreated(acc)
			So(err, ShouldBeNil)
			So(doBasicTestForAccount(handler, acc.OldId), ShouldBeNil)

			err = handler.ParticipantCreated(cp)
			So(err, ShouldBeNil)

			So(doBasicTestForAccount(handler, acc.OldId), ShouldBeNil)
			So(makeSureHasTag(handler, acc.OldId, strconv.FormatInt(tc1.Id, 10)), ShouldBeNil)

			Convey("trying to add again should success", func() {
				err = handler.ParticipantCreated(cp)
				So(err, ShouldBeNil)

				So(doBasicTestForAccount(handler, acc.OldId), ShouldBeNil)
				So(makeSureHasTag(handler, acc.OldId, strconv.FormatInt(tc1.Id, 10)), ShouldBeNil)
				So(makeSureTagLen(handler, acc.OldId, 2), ShouldBeNil)
			})
		})

		Convey("when the account is not on algolia", func() {
			err = handler.ParticipantCreated(cp)
			So(err, ShouldBeNil)

			So(doBasicTestForAccount(handler, acc.OldId), ShouldBeNil)
			So(makeSureHasTag(handler, acc.OldId, strconv.FormatInt(tc1.Id, 10)), ShouldBeNil)
			So(makeSureTagLen(handler, acc.OldId, 1), ShouldBeNil)
		})
	})
}
Ejemplo n.º 13
0
func TestCollaborationSesionEnd(t *testing.T) {
	r := runner.New("collaboration-tests")
	err := r.Init()
	if err != nil {
		panic(err)
	}

	defer r.Close()

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

	Convey("while testing collaboration session end", t, func() {

		Convey("we should be able to create a doc on google drive", func() {
			Convey("we should be able to delete a created doc", func() {
				Convey("deleting an already deleted doc should not give error", func() {
				})
			})
		})

		Convey("trying to delete a non-existing doc should not give error", func() {
		})
	})

	Convey("while pinging collaboration", t, func() {
		// owner
		owner, err := apimodels.CreateAccountInBothDbs()
		So(err, ShouldBeNil)
		So(owner, ShouldNotBeNil)

		groupName := apimodels.RandomGroupName()
		apimodels.CreateTypedGroupedChannelWithTest(
			owner.Id,
			apimodels.Channel_TYPE_GROUP,
			groupName,
		)

		ownerSession, err := modelhelper.FetchOrCreateSession(owner.Nick, groupName)
		So(err, ShouldBeNil)
		So(ownerSession, ShouldNotBeNil)

		Convey("reponse should be success", func() {
			p := &models.Ping{
				AccountId: 1,
				FileId:    "hello",
			}

			res, err := rest.CollaborationPing(p, ownerSession.ClientId)
			So(err, ShouldBeNil)
			So(res, ShouldNotBeNil)
		})
	})
}
Ejemplo n.º 14
0
func WithRunner(t *testing.T, f func(*runner.Runner)) {
	r := runner.New("test")
	if err := r.Init(); err != nil {
		t.Fatalf("couldnt start bongo %s", err.Error())
	}
	defer r.Close()

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

	f(r)
}
Ejemplo n.º 15
0
func WithConfiguration(t *testing.T, f func(c *config.Config)) {
	r := runner.New("test")
	if err := r.Init(); err != nil {
		t.Fatal(err.Error())
	}
	defer r.Close()

	c := config.MustRead(r.Conf.Path)
	modelhelper.Initialize(c.Mongo)
	defer modelhelper.Close()

	f(c)
}
Ejemplo n.º 16
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")

}
Ejemplo n.º 17
0
func main() {
	r := runner.New(name)
	if err := r.Init(); err != nil {
		log.Fatal(err.Error())
	}

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

	r.SetContext(presence.New(r.Log, appConfig))
	r.Register(presence.Ping{}).On(presence.EventName).Handle((*presence.Controller).Ping)
	r.Listen()
	r.Wait()
}
Ejemplo n.º 18
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
		}
	}
}
Ejemplo n.º 19
0
func main() {
	r := runner.New(Name)
	if err := r.Init(); err != nil {
		log.Fatal(err)
	}

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

	if err := models.DeleteDiffedDBAccounts(); err != nil {
		fmt.Println("error while deleting account that non-existing in mongo", err)
		return
	}

}
Ejemplo n.º 20
0
func TestGetSocialIdFromEmail(t *testing.T) {
	r := runner.New("test")
	if err := r.Init(); err != nil {
		t.Fatalf("couldnt start bongo %s", err.Error())
	}
	defer r.Close()

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

	Convey("while getting account id in the mail", t, func() {
		Convey("From fields should be saved in db, otherwise return err", func() {

			m := &Mail{
				From: "mailisnotexist@abo",
			}

			gid, err := m.getSocialIdFromEmail()
			So(err, ShouldNotBeNil)
			So(err, ShouldEqual, ErrEmailIsNotFetched)
			So(gid, ShouldEqual, 0)
		})

		Convey("should not be any error if all is well", func() {

			acc, err := socialapimodels.CreateAccountInBothDbs()
			So(err, ShouldBeNil)

			mongoUser, err := modelhelper.GetUser(acc.Nick)
			So(err, ShouldBeNil)

			m := &Mail{
				From: mongoUser.Email,
			}

			gid, err := m.getSocialIdFromEmail()
			So(err, ShouldBeNil)
			So(gid, ShouldEqual, acc.Id)

		})

	})
}
Ejemplo n.º 21
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)
	}

}
Ejemplo n.º 22
0
func TestCollaborationOperationsDeleteDriveDoc(t *testing.T) {
	r := runner.New("collaboration-DeleteDriveDoc-tests")
	err := r.Init()
	if err != nil {
		panic(err)
	}

	defer r.Close()

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

	// init with defaults
	mongoCache := cache.NewMongoCacheWithTTL(modelhelper.Mongo.Session)
	defer mongoCache.StopGC()

	handler := New(r.Log, mongoCache, appConfig, r.Kite)

	Convey("while testing DeleteDriveDoc", t, func() {
		req := &models.Ping{
			AccountId: 1,
			FileId:    fmt.Sprintf("%d", rand.Int63()),
		}
		Convey("should be able to create the file", func() {
			f, err := createTestFile(handler)
			So(err, ShouldBeNil)
			req.FileId = f.Id

			Convey("should be able to delete the created file", func() {
				err = handler.DeleteDriveDoc(req)
				So(err, ShouldBeNil)
			})

			Convey("if file id is nil response should be nil", func() {
				req := req
				req.FileId = ""
				err = handler.DeleteDriveDoc(req)
				So(err, ShouldBeNil)
			})
		})
	})
}
Ejemplo n.º 23
0
func TestGetAccount(t *testing.T) {
	r := runner.New("test")
	if err := r.Init(); err != nil {
		t.Fatalf("couldnt start bongo %s", err.Error())
	}
	defer r.Close()

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

	Convey("while testing get account", t, func() {
		Convey("returns empty if parameter is invalid", func() {
			acc, err := GetAccount("interestingEmail@somethinglikethat")
			So(err, ShouldNotBeNil)
			So(acc, ShouldBeNil)
		})

		Convey("returns empty if parameter is empty", func() {
			acc, err := GetAccount("")
			So(err, ShouldNotBeNil)
			So(acc, ShouldBeNil)
		})

		Convey("Should return blank if parameter is empty", func() {
			acc, err := socialapimodels.CreateAccountInBothDbs()
			So(err, ShouldBeNil)

			mongoUser, err := modelhelper.GetUser(acc.Nick)
			So(err, ShouldBeNil)

			m := &Mail{
				From: mongoUser.Email,
			}
			ga, err := GetAccount(m.From)
			So(err, ShouldBeNil)
			So(ga, ShouldNotBeNil)
		})

	})
}
Ejemplo n.º 24
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
		}
	}
}
Ejemplo n.º 25
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()
}
Ejemplo n.º 26
0
func TestMailParse(t *testing.T) {
	r := runner.New("test")
	err := r.Init()
	if err != nil {
		panic(err)
	}

	defer r.Close()

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

	Convey("while sending mail", t, func() {

		Convey("reponse should be success", func() {
			acc, err := socialapimodels.CreateAccountInBothDbs()
			So(err, ShouldBeNil)

			c := socialapimodels.CreateChannelWithTest(acc.Id)
			socialapimodels.AddParticipantsWithTest(c.Id, acc.Id)

			cm := socialapimodels.CreateMessage(c.Id, acc.Id, socialapimodels.ChannelMessage_TYPE_POST)
			So(cm, ShouldNotBeNil)

			mongoUser, err := modelhelper.GetUser(acc.Nick)
			So(err, ShouldBeNil)

			p := &models.Mail{
				From:              mongoUser.Email,
				OriginalRecipient: fmt.Sprintf("*****@*****.**", c.Id),
				MailboxHash:       fmt.Sprintf("messageid.%d", cm.Id),
				TextBody:          "Its an example of text message",
				StrippedTextReply: "This one is reply message",
			}

			res, err := rest.MailParse(p)
			So(err, ShouldBeNil)
			So(res, ShouldNotBeNil)
		})
	})
}
Ejemplo n.º 27
0
func main() {
	r := runner.New(Name)
	if err := r.Init(); err != nil {
		log.Fatal(err)
	}

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

	r.SetContext(team.NewController(r.Log, appConfig))
	r.Register(models.ChannelParticipant{}).OnCreate().Handle((*team.Controller).HandleParticipant)
	r.Register(models.ChannelParticipant{}).OnUpdate().Handle((*team.Controller).HandleParticipant)
	r.Register(models.ChannelParticipant{}).OnDelete().Handle((*team.Controller).HandleParticipant)
	r.Register(models.Channel{}).OnCreate().Handle((*team.Controller).HandleCreator)
	r.Register(models.Channel{}).OnDelete().Handle((*team.Controller).HandleChannel)
	r.Listen()
	r.Wait()
}
Ejemplo n.º 28
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()
}
Ejemplo n.º 29
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)
	}
}
Ejemplo n.º 30
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()
}