コード例 #1
0
ファイル: application.go プロジェクト: dieucao/notifications
func (app Application) StartWorkers() {
	zonedUAAClient := uaa.NewZonedUAAClient(app.env.UAAClientID, app.env.UAAClientSecret, app.env.VerifySSL, UAAPublicKey)

	WorkerGenerator{
		InstanceIndex: app.env.VCAPApplication.InstanceIndex,
		Count:         WorkerCount,
	}.Work(func(i int) Worker {
		cloak, err := conceal.NewCloak(app.env.EncryptionKey)
		if err != nil {
			panic(err)
		}
		v1Workflow := postal.NewV1Process(postal.V1ProcessConfig{
			DBTrace: app.env.DBLoggingEnabled,
			UAAHost: app.env.UAAHost,
			Sender:  app.env.Sender,
			Domain:  app.env.Domain,

			Packager:    postal.NewPackager(app.mother.TemplatesLoader(), cloak),
			MailClient:  app.mother.MailClient(),
			Database:    app.mother.Database(),
			TokenLoader: uaa.NewTokenLoader(zonedUAAClient),
			UserLoader:  postal.NewUserLoader(zonedUAAClient),

			KindsRepo:              app.mother.KindsRepo(),
			ReceiptsRepo:           app.mother.ReceiptsRepo(),
			UnsubscribesRepo:       app.mother.UnsubscribesRepo(),
			GlobalUnsubscribesRepo: app.mother.GlobalUnsubscribesRepo(),
			MessageStatusUpdater:   postal.NewMessageStatusUpdater(app.mother.MessagesRepo()),
			DeliveryFailureHandler: postal.NewDeliveryFailureHandler(),
		})

		database := v2models.NewDatabase(app.mother.SQLDatabase(), v2models.Config{})
		messageStatusUpdater := postal.NewV2MessageStatusUpdater(v2models.NewMessagesRepository(util.NewClock()))
		v2Workflow := postal.NewV2Workflow(app.mother.MailClient(), postal.NewPackager(app.mother.TemplatesLoader(), cloak), postal.NewUserLoader(zonedUAAClient), uaa.NewTokenLoader(zonedUAAClient), messageStatusUpdater, database, app.env.Sender, app.env.Domain, app.env.UAAHost)

		worker := postal.NewDeliveryWorker(v1Workflow, v2Workflow, postal.DeliveryWorkerConfig{
			ID:                     i,
			UAAHost:                app.env.UAAHost,
			Logger:                 app.mother.Logger(),
			Queue:                  app.mother.Queue(),
			DBTrace:                app.env.DBLoggingEnabled,
			Database:               database,
			StrategyDeterminer:     strategy.NewStrategyDeterminer(app.mother.UserStrategy(), app.mother.SpaceStrategy(), app.mother.OrganizationStrategy(), app.mother.EmailStrategy()),
			DeliveryFailureHandler: postal.NewDeliveryFailureHandler(),
			MessageStatusUpdater:   messageStatusUpdater,
		})
		return &worker
	})
}
コード例 #2
0
			ClientID: "some-client-id",
			Options: postal.Options{
				Subject:    "Some crazy subject",
				TemplateID: "some-template-id",
				KindID:     "some-kind-id",
				HTML: postal.HTML{
					BodyContent:    "<p>user supplied banana html</p>",
					BodyAttributes: "class=\"bananaBody\"",
					Head:           "<title>The title</title>",
					Doctype:        "<!DOCTYPE html>",
				},
				Text: "some-text",
			},
		}

		packager = postal.NewPackager(templatesLoader, cloak)

		requestReceivedTime, _ := time.Parse(time.RFC3339Nano, "2015-06-08T14:38:03.180764129-07:00")

		context = postal.MessageContext{
			From:      "banana man",
			ReplyTo:   "awesomeness",
			To:        "endless monkeys",
			Subject:   "we will be eaten",
			ClientID:  "3&3",
			MessageID: "4'4",
			Text:      "User <supplied> \"banana\" text",
			UserGUID:  "user-123",
			HTMLComponents: postal.HTML{
				BodyContent:    "<p>user supplied banana html</p>",
				BodyAttributes: "class=\"bananaBody\"",
コード例 #3
0
			Subject: "{{.Subject}}",
		}
		receiptsRepo = mocks.NewReceiptsRepo()
		messageStatusUpdater = mocks.NewMessageStatusUpdater()
		deliveryFailureHandler = mocks.NewDeliveryFailureHandler()

		cloak, err := conceal.NewCloak(encryptionKey)
		Expect(err).NotTo(HaveOccurred())

		v1Process = postal.NewV1Process(postal.V1ProcessConfig{
			DBTrace: false,
			UAAHost: "https://uaa.example.com",
			Sender:  "*****@*****.**",
			Domain:  "example.com",

			Packager:    postal.NewPackager(templateLoader, cloak),
			MailClient:  mailClient,
			Database:    database,
			TokenLoader: tokenLoader,
			UserLoader:  userLoader,

			KindsRepo:              kindsRepo,
			ReceiptsRepo:           receiptsRepo,
			UnsubscribesRepo:       unsubscribesRepo,
			GlobalUnsubscribesRepo: globalUnsubscribesRepo,
			MessageStatusUpdater:   messageStatusUpdater,
			DeliveryFailureHandler: deliveryFailureHandler,
		})

		messageID = "randomly-generated-guid"
		delivery = postal.Delivery{