コード例 #1
0
ファイル: mongodb_test.go プロジェクト: gooops/machinery
func TestMongodbDropIndexes(t *testing.T) {
	conf := &config.Config{
		ResultBackend:   MongoDBConnectionString,
		ResultsExpireIn: 5,
	}

	_, err := backends.NewMongodbBackend(conf)
	assert.NoError(t, err)

	conf.ResultsExpireIn = 7

	_, err = backends.NewMongodbBackend(conf)
	assert.NoError(t, err)
}
コード例 #2
0
ファイル: factories.go プロジェクト: gooops/machinery
// BackendFactory creates a new object with backends.Backend interface
// Currently supported backends are AMQP and Memcache
func BackendFactory(cnf *config.Config) (backends.Backend, error) {
	if strings.HasPrefix(cnf.ResultBackend, "amqp://") {
		return backends.NewAMQPBackend(cnf), nil
	}

	if strings.HasPrefix(cnf.ResultBackend, "memcache://") {
		parts := strings.Split(cnf.ResultBackend, "memcache://")
		if len(parts) != 2 {
			return nil, fmt.Errorf(
				"Memcache result backend connection string should be in format memcache://server1:port,server2:port, instead got %s",
				cnf.ResultBackend,
			)
		}
		servers := strings.Split(parts[1], ",")
		return backends.NewMemcacheBackend(cnf, servers), nil
	}

	if strings.HasPrefix(cnf.ResultBackend, "redis://") {
		redisHost, redisPassword, redisDB, err := ParseRedisURL(cnf.ResultBackend)
		if err != nil {
			return nil, err
		}

		return backends.NewRedisBackend(cnf, redisHost, redisPassword, "", redisDB), nil
	}

	if strings.HasPrefix(cnf.ResultBackend, "redis+socket://") {
		redisSocket, redisPassword, redisDB, err := ParseRedisSocketURL(cnf.ResultBackend)
		if err != nil {
			return nil, err
		}

		return backends.NewRedisBackend(cnf, "", redisPassword, redisSocket, redisDB), nil
	}

	if strings.HasPrefix(cnf.ResultBackend, "mongodb://") {
		return backends.NewMongodbBackend(cnf)
	}

	if strings.HasPrefix(cnf.ResultBackend, "eager") {
		return backends.NewEagerBackend(), nil
	}

	return nil, fmt.Errorf("Factory failed with result backend: %v", cnf.ResultBackend)
}
コード例 #3
0
ファイル: mongodb_test.go プロジェクト: gooops/machinery
func initTestMongodbBackend() (backends.Backend, error) {
	conf := &config.Config{
		ResultBackend:   MongoDBConnectionString,
		ResultsExpireIn: 30,
	}
	backend, err := backends.NewMongodbBackend(conf)
	if err != nil {
		return nil, err
	}

	err = backend.PurgeGroupMeta(groupUUID)
	if err != nil {
		return nil, err
	}
	err = backend.InitGroup(groupUUID, taskUUIDs)
	if err != nil {
		return nil, err
	}
	return backend, nil
}