Esempio n. 1
0
func init() {
	// Parse the flags
	flag.Parse()

	cnf = config.Config{
		Broker:        *broker,
		ResultBackend: *resultBackend,
		Exchange:      *exchange,
		ExchangeType:  *exchangeType,
		DefaultQueue:  *defaultQueue,
		BindingKey:    *bindingKey,
	}

	// Parse the config
	// NOTE: If a config file is present, it has priority over flags
	data, err := config.ReadFromFile(*configPath)
	if err == nil {
		err = config.ParseYAMLConfig(&data, &cnf)
		errors.Fail(err, "Could not parse config file")
	}

	server, err := machinery.NewServer(&cnf)
	errors.Fail(err, "Could not initialize server")

	// Register tasks
	tasks := map[string]interface{}{
		"add":      exampletasks.Add,
		"multiply": exampletasks.Multiply,
	}
	server.RegisterTasks(tasks)

	// The second argument is a consumer tag
	// Ideally, each worker should have a unique tag (worker1, worker2 etc)
	worker = server.NewWorker("machinery_worker")
}
Esempio n. 2
0
func TestParseYAMLConfig(t *testing.T) {
	data := []byte(configYAMLData)
	cfg := new(config.Config)
	config.ParseYAMLConfig(&data, cfg)

	assert.Equal(t, "amqp://*****:*****@localhost:5672/", cfg.Broker)
	assert.Equal(t, "amqp", cfg.ResultBackend)
	assert.Equal(t, 3600000, cfg.ResultsExpireIn)
	assert.Equal(t, "machinery_exchange", cfg.Exchange)
	assert.Equal(t, "direct", cfg.ExchangeType)
	assert.Equal(t, "machinery_tasks", cfg.DefaultQueue)
	assert.Equal(t, "machinery_task", cfg.BindingKey)
	assert.Equal(t, "any", cfg.QueueBindingArguments["x-match"])
	assert.Equal(t, "png", cfg.QueueBindingArguments["image-type"])
}
Esempio n. 3
0
func init() {
	// Parse the flags
	flag.Parse()

	cnf = config.Config{
		Broker:        *broker,
		ResultBackend: *resultBackend,
		Exchange:      *exchange,
		ExchangeType:  *exchangeType,
		DefaultQueue:  *defaultQueue,
		BindingKey:    *bindingKey,
	}

	// Parse the config
	// NOTE: If a config file is present, it has priority over flags
	data, err := config.ReadFromFile(*configPath)
	if err == nil {
		err = config.ParseYAMLConfig(&data, &cnf)
		errors.Fail(err, "Could not parse config file")
	}

	server, err = machinery.NewServer(&cnf)
	errors.Fail(err, "Could not initialize server")
}