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") }
func TestReadFromFile(t *testing.T) { data, err := config.ReadFromFile("testconfig.yml") if string(data) == configYAMLData && err == nil { return } var buffer bytes.Buffer buffer.WriteString( fmt.Sprintf("Expected value:\n%v\n", configYAMLData)) buffer.WriteString( fmt.Sprintf("Actual value:\n%v\n", string(data))) t.Error(buffer.String()) }
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") }