示例#1
0
文件: main.go 项目: altlinux/webery
func main() {
	flag.Parse()

	cfg, err := config.NewConfig(*configFile)
	if err != nil {
		log.Fatal(err)
	}

	dbi := storage.NewSession(cfg.Mongo)
	defer dbi.Close()

	col, err := dbi.Coll("tasks")
	if err != nil {
		log.Fatal(err)
	}

	iter := col.Find(db.QueryDoc{"events": db.QueryDoc{"$exists": false}}).Iter()
	for {
		o := make(db.QueryDoc)
		if !iter.Next(o) {
			break
		}

		//fmt.Printf("%d\n", o["taskid"])

		taskid, ok := o["taskid"].(int64)
		if !ok {
			fmt.Printf("%d: error taskid not found\n", o["taskid"])
			continue
		}

		try, ok := o["try"].(int64)
		if !ok {
			fmt.Printf("%d: error try not found\n", o["taskid"])
			continue
		}

		var events []string
		for i := int64(1); i <= try; i += 1 {
			events = append(events, fmt.Sprintf("%d.1", i))
		}
		o["events"] = events

		s := db.QueryDoc{
			"taskid": taskid,
		}
		d := db.QueryDoc{
			"$set": db.QueryDoc{"events": events},
		}

		if err := col.Update(s, d); err != nil {
			fmt.Printf("%d: mongo error: %v\n", o["taskid"], err)
			break
		}
	}
	fmt.Printf("OK\n")
}
示例#2
0
文件: webery.go 项目: altlinux/webery
func main() {
	flag.Parse()

	cfg, err := config.NewConfig(*configFile)
	if err != nil {
		log.Fatal(err)
	}

	log.SetLevel(cfg.Logging.Level.Level)
	log.SetFormatter(&log.TextFormatter{
		FullTimestamp:    cfg.Logging.FullTimestamp,
		DisableTimestamp: cfg.Logging.DisableTimestamp,
		DisableColors:    cfg.Logging.DisableColors,
		DisableSorting:   cfg.Logging.DisableSorting,
	})

	pidFile, err := pidfile.OpenPidfile(cfg.Global.Pidfile)
	if err != nil {
		log.Fatal("Unable to open pidfile: ", err.Error())
	}
	defer pidFile.Close()

	if err := pidFile.Check(); err != nil {
		log.Fatal("Check failed: ", err.Error())
	}

	if err := pidFile.Write(); err != nil {
		log.Fatal("Unable to write pidfile: ", err.Error())
	}

	logFile, err := logfile.OpenLogfile(cfg.Global.Logfile)
	if err != nil {
		log.Fatal("Unable to open log: ", err.Error())
	}
	defer logFile.Close()
	log.SetOutput(logFile)

	dbi := storage.NewSession(cfg.Mongo)
	defer dbi.Close()

	server := Server{
		Cfg: cfg,
		DB:  dbi,
	}

	http.HandleFunc("/", server.Handler)
	log.Fatal(http.ListenAndServe(cfg.Global.Address, nil))
}