Beispiel #1
0
func main() {
	flag.Parse()

	fmt.Println("Icarus Server")
	fmt.Println("-------------")

	disp := server.NewDispatcher(1024, client.RegisteredList())

	go func() {
		log.Infof("Task Handler at %s", *flagTaskBind)
		mux := http.NewServeMux()
		mux.Handle("/", disp)
		panic(http.ListenAndServe(*flagTaskBind, mux))
	}()

	// Start all tasks
	manager.InitManager()
	{
		tasks := manager.ListTasks()
		for _, task := range tasks {
			task.Start()
		}
	}

	log.Infof("API Handler at %s", *flagAPIBind)
	handler.InitHandler()
	var handler http.Handler = http.DefaultServeMux
	if *flagCORS {
		c := cors.New(cors.Options{
			AllowedOrigins:   []string{"*"},
			AllowedMethods:   []string{"GET", "PUT", "POST", "PATCH", "DELETE"},
			AllowedHeaders:   []string{"*"},
			AllowCredentials: true,
		})
		handler = c.Handler(handler)
	}
	panic(http.ListenAndServe(*flagAPIBind, context.ClearHandler(handler)))
}
Beispiel #2
0
		resp := &dispatcher.SubtaskResult{
			Data: []string{strings.Join(sb.Data, sep)},
		}

		time.Sleep(delay)
		err = pm.SendResult(resp)
		if err == satellite.ErrTaskVanished {
			log.Warnf("Satellite %s: Task %d has gone!", name, sb.ID)
		} else if err != nil {
			log.Warnf("Satellite %s: Task %d: %s", name, sb.ID, err.Error())
		}
	}
}

var disp = server.NewDispatcher(1024, []string{"comma", "dot", "space"})
var once sync.Once

func initDispatcher() {
	once.Do(func() {
		go func() {
			log.Printf("Task Handler at %s", *flagTaskBind)
			mux := http.NewServeMux()
			mux.Handle("/", disp)
			panic(http.ListenAndServe(*flagTaskBind, mux))
		}()
		time.Sleep(time.Second * 2)
	})
}

func TestDispatcherBasic(t *testing.T) {