コード例 #1
0
ファイル: main.go プロジェクト: bkcsoft/gorunner
func main() {
	wd, _ := os.Getwd()
	log.Println("Working directory", wd)

	// We need `./db/`...
	if dbStat, err := os.Stat(`./db`); err != nil || !dbStat.IsDir() {
		os.Mkdir(`./db`, 0700)
	}

	loadSettings("db/app.ini")
	log.Println("Writing logs to ", Settings.LogFile)
	if Settings.LogFile != "" {
		f, err := os.OpenFile(Settings.LogFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
		if err != nil {
			log.Printf("Can't open logfile! `%s` | Error: %#v\n", Settings.LogFile, err)
			os.Exit(1)
		}
		defer f.Close()
		log.SetOutput(f)
	}

	jobList := service.NewJobList()
	taskList := service.NewTaskList()
	triggerList := service.NewTriggerList()
	runList := service.NewRunList(jobList)

	jobList.Load()
	taskList.Load()
	triggerList.Load()
	runList.Load()

	hub := service.NewHub(runList)
	go hub.HubLoop()

	executor := service.NewExecutor(jobList, taskList, runList)

	appContext := &ctx{hub, executor, jobList, taskList, triggerList, runList}

	r := mux.NewRouter()

	// non REST routes
	r.PathPrefix("/static/").Handler(http.FileServer(http.Dir("web/")))
	r.HandleFunc("/", app).Methods("GET")
	r.HandleFunc("/favicon.ico", favicon).Methods("GET")
	r.Handle("/ws", appHandler{appContext, wsHandler}).Methods("GET")

	for _, detail := range routes {
		r.Handle(detail.route, appHandler{appContext, detail.handler}).Methods(detail.method)
	}

	host := Settings.ServeIP + ":" + strconv.Itoa(Settings.HTTPPort)

	log.Println("Running on " + host)
	if Settings.LogFile == "" {
		log.Println("Not logging to file, restart disabled...")
		http.ListenAndServe(host, r)
	} else {
		endless.ListenAndServe(host, r)
	}
}
コード例 #2
0
ファイル: handlers_test.go プロジェクト: bkcsoft/gorunner
func TestResponses(t *testing.T) {
	w := httptest.NewRecorder()

	uri := "/jobs"
	param := make(url.Values)

	r, err := http.NewRequest("GET", uri+param.Encode(), nil)
	if err != nil {
		t.Fatal(err)
	}

	jobList := service.NewJobList()
	c := ctx{jobList: jobList}

	status, _ := listJobs(c, w, r)

	if status != http.StatusOK {
		t.Errorf("Expected %v, %v; got %v, %v", http.StatusOK, status)
	}
}