Example #1
0
func main() {
	var configFile string
	var dispatcherId uint64
	var listen string

	pwd, err := os.Getwd()
	if err != nil {
		log.Fatalf("Could not determine current working directory")
	}

	defaultConfig := path.Join(pwd, "etc", "config.gcfg")

	flag.Uint64Var(
		&dispatcherId,
		"id",
		0,
		"Dispatcher ID, overrides config file settings",
	)
	flag.StringVar(
		&listen,
		"listen",
		"",
		"host:port to listen on",
	)
	flag.StringVar(
		&configFile,
		"config",
		defaultConfig,
		"Path to config file",
	)
	flag.Parse()

	os.Setenv("STF_CONFIG", configFile)
	config, err := config.BootstrapConfig()
	if err != nil {
		log.Fatal(err)
	}

	if dispatcherId > 0 {
		config.Dispatcher.ServerId = dispatcherId
	}
	if listen != "" {
		config.Dispatcher.Listen = listen
	}

	d := dispatcher.New(config)
	d.Start()
}
func ExampleScopedContext() {
	config, err := config.BootstrapConfig()
	if err != nil {
		log.Fatalf("Failed to bootstrap config: %s", err)
	}

	for {
		ctx := NewContext(config)
		rollback, err := ctx.TxnBegin()
		if err != nil {
			log.Fatalf("Failed to start transaction: %s", err)
		}
		defer rollback()

		// Do stuff...
		ctx.TxnCommit()
	}
}
Example #3
0
func main() {
	var configFile string

	pwd, err := os.Getwd()
	if err != nil {
		log.Fatalf("Could not determine current working directory")
	}

	defaultConfig := path.Join(pwd, "etc", "config.gcfg")

	flag.StringVar(
		&configFile,
		"config",
		defaultConfig,
		"Path to config file",
	)
	flag.Parse()

	os.Setenv("STF_CONFIG", configFile)

	config, err := config.BootstrapConfig()
	if err != nil {
		log.Fatalf("Could not load config: %s", err)
	}

	// Get our path, and add this to PATH, so other binaries
	// can safely be executed
	dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
	if err != nil {
		log.Fatalf("Failed to find our directory name?!: %s", err)
	}

	p := os.Getenv("PATH")
	os.Setenv("PATH", strings.Join([]string{p, dir}, ":"))

	drone.NewDrone(config).Run()
}
Example #4
0
func (w *BaseWorker) Run() {
	closer := stf.LogMark("[Worker:%s]", w.name)
	defer closer()

	var configFile string

	pwd, err := os.Getwd()
	if err != nil {
		log.Fatalf("Could not determine current working directory")
	}

	defaultConfig := path.Join(pwd, "etc", "config.gcfg")

	flag.StringVar(
		&configFile,
		"config",
		defaultConfig,
		"Path to config file",
	)
	flag.Parse()

	os.Setenv("STF_CONFIG", configFile)

	cfg, err := config.BootstrapConfig()
	if err != nil {
		stf.Debugf("Failed to load config: %s", err)
		return
	}

	w.ctx = api.NewContext(cfg)

	w.SendCmd(CmdWorkerSlaveSpawn)

	w.MainLoop()
	stf.Debugf("Worker exiting")
}
Example #5
0
func (self *TestEnv) Setup() {
	if home := os.Getenv("STF_HOME"); home != "" {
		oldpath := os.Getenv("PATH")
		newpath := path.Join(home, "bin")
		self.Test.Logf("Adding %s to path", newpath)
		os.Setenv("PATH", strings.Join([]string{newpath, oldpath}, ":"))
	}

	self.createTemporaryDir()
	self.startDatabase()
	self.startQueue()
	self.startMemcached()
	self.createTemporaryConfig()
	self.startTemporaryStorageServers()
	self.startWorkers()

	os.Setenv("STF_CONFIG", self.ConfigFile.Name())
	config, err := config.BootstrapConfig()
	if err != nil {
		self.Test.Fatalf("%s", err)
	}

	self.Ctx = api.NewContext(config)
}