コード例 #1
0
ファイル: etcd.go プロジェクト: leobcn/gru
// Creates a new etcd minion
func NewEtcdMinion(name string, cfg etcdclient.Config) Minion {
	c, err := etcdclient.New(cfg)
	if err != nil {
		log.Fatal(err)
	}

	kapi := etcdclient.NewKeysAPI(c)
	id := utils.GenerateUUID(name)
	rootDir := filepath.Join(EtcdMinionSpace, id.String())
	queueDir := filepath.Join(rootDir, "queue")
	classifierDir := filepath.Join(rootDir, "classifier")
	logDir := filepath.Join(rootDir, "log")
	taskQueue := make(chan *task.Task)
	done := make(chan struct{})

	m := &etcdMinion{
		name:          name,
		rootDir:       rootDir,
		queueDir:      queueDir,
		classifierDir: classifierDir,
		logDir:        logDir,
		id:            id,
		kapi:          kapi,
		taskQueue:     taskQueue,
		done:          done,
	}

	return m
}
コード例 #2
0
ファイル: etcd.go プロジェクト: ycaille/gru
// NewEtcdMinion creates a new minion with etcd backend
func NewEtcdMinion(config *EtcdMinionConfig) (Minion, error) {
	c, err := etcdclient.New(config.EtcdConfig)
	if err != nil {
		return nil, err
	}

	cwd, err := os.Getwd()
	if err != nil {
		return nil, err
	}

	gitRepo, err := utils.NewGitRepo(filepath.Join(cwd, "site"), config.SiteRepo)
	if err != nil {
		return nil, err
	}

	id := utils.GenerateUUID(config.Name)
	rootDir := filepath.Join(EtcdMinionSpace, id.String())
	m := &etcdMinion{
		name:          config.Name,
		rootDir:       rootDir,
		queueDir:      filepath.Join(rootDir, "queue"),
		classifierDir: filepath.Join(rootDir, "classifier"),
		logDir:        filepath.Join(rootDir, "log"),
		id:            id,
		kapi:          etcdclient.NewKeysAPI(c),
		taskQueue:     make(chan *task.Task),
		gitRepo:       gitRepo,
		done:          make(chan struct{}),
	}

	return m, nil
}