Example #1
0
func buildApp() kit.App {
	app := NewApp("")

	conf := app.Registry().Config()
	conf.Set("host", "localhost")
	conf.Set("port", 10010)
	conf.Set("url", "http://localhost:10010")

	conf.Set("users.emailConfirmationPath", "?confirm-email={token}")
	conf.Set("users.passwordResetPath", "?reset-password={token}")

	backend := memory.New()
	app.RegisterBackend(backend)

	// Build user service.

	userService := users.NewService(nil, backend, &UserProfile{})
	app.RegisterUserService(userService)

	// Register facebook oauth service.
	appId := "170108689991460"
	appSecret := "cb91c245199a3d3b19fdccbe0c7f93a0"
	fbService := oauth.NewFacebook(appId, appSecret)
	userService.AuthAdaptor("oauth").(*oauth.AuthAdaptorOauth).RegisterService(fbService)

	// Persist log messages in logMessages.
	app.Logger().Hooks.Add(LoggerHook{})

	app.PrepareBackends()

	return app
}
Example #2
0
func buildBackend() db.Backend {
	b := memory.New()

	b.RegisterModel(&tests.TestModel{})
	b.RegisterModel(&tests.TestParent{})

	return b
}
Example #3
0
func BuildApp() appkit.App {
	app := app.NewApp()

	// Set up memory backend.
	backend := memory.New()
	app.RegisterBackend(backend)

	// Set up resources.
	app.RegisterResource(resources.NewResource(&Project{}, &resources.UserResource{}, true))
	app.RegisterResource(resources.NewResource(&Todo{}, &resources.UserResource{}, true))

	return app
}
Example #4
0
func buildRegistry() kit.Registry {
	registry := app.NewRegistry()

	logger := &logrus.Logger{
		Out:       os.Stderr,
		Formatter: new(logrus.TextFormatter),
		Hooks:     make(logrus.LevelHooks),
		Level:     logrus.DebugLevel,
	}
	registry.SetLogger(logger)

	backend := memory.New()
	registry.AddBackend(backend)

	service := NewService(registry, backend)
	registry.SetTaskService(service)

	runner := service.Runner

	t1 := &TaskSpec{
		Name:           "task1",
		RetryInterval:  time.Duration(2) * time.Second,
		AllowedRetries: 3,
		Handler: func(reg kit.Registry, data interface{}) (interface{}, apperror.Error, bool) {
			v, ok := data.(int64)
			if !ok {
				return nil, apperror.New("invalid_data"), false
			}

			return v * 2, nil, false
		},
	}
	runner.RegisterTask(t1)

	failCounter := 2
	t2 := &TaskSpec{
		Name:           "task2",
		RetryInterval:  time.Duration(1) * time.Second,
		AllowedRetries: 3,
		Handler: func(reg kit.Registry, data interface{}) (interface{}, apperror.Error, bool) {
			reg.Logger().Infof("runCounter: %v", failCounter)
			if failCounter > 0 {
				failCounter -= 1
				return nil, apperror.New("failed"), true
			} else {
				return data.(int64) * 2, nil, false
			}
		},
	}
	runner.RegisterTask(t2)

	t3 := &TaskSpec{
		Name:           "task_sleeping",
		RetryInterval:  time.Duration(2) * time.Second,
		AllowedRetries: 3,
		Handler: func(reg kit.Registry, data interface{}) (interface{}, apperror.Error, bool) {
			v := data.(int)
			time.Sleep(time.Duration(v) * time.Millisecond)

			return 1, nil, false
		},
	}
	runner.RegisterTask(t3)

	return registry
}