コード例 #1
0
ファイル: process.go プロジェクト: haste/tiers
func ProcessQueueHandler(w http.ResponseWriter, r *http.Request) {
	session, _ := session.Get(r, "tiers")
	userid, _ := session.Values["user"]

	owner := mux.Vars(r)["owner"]
	ownerInt, _ := strconv.Atoi(owner)

	faulty := mux.Vars(r)["faulty"]
	faultyInt, _ := strconv.Atoi(faulty)
	row := model.GetQueueWithProfileById(faultyInt)
	defer row.Close()

	row.Next()
	faultyProfile := rowToQueueProfile(row)

	previous := mux.Vars(r)["previous"]
	previousInt, _ := strconv.Atoi(previous)
	row = model.GetQueueWithProfileById(previousInt)
	defer row.Close()

	row.Next()
	previousProfile := rowToQueueProfile(row)

	o := ocr.New(faultyProfile.File, 0)

	o.Split()
	o.Process()
	o.CleanUp()

	templates := loadTemplates(
		"header.html",
		"footer.html",
		"nav.html",
		"admin/processQueue.html",
	)

	templates.ExecuteTemplate(w, "processQueue", struct {
		User     int
		Owner    int
		File     string
		Faulty   userQueueEntry
		Previous userQueueEntry
		Dry      profile.Profile
	}{
		User:     userid.(int),
		Owner:    ownerInt,
		Faulty:   faultyProfile,
		Previous: previousProfile,
		Dry:      o.Profile,
	})
}
コード例 #2
0
ファイル: process.go プロジェクト: haste/tiers
func ProcessRunHandler(w http.ResponseWriter, r *http.Request) {
	faulty := mux.Vars(r)["faulty"]
	faultyInt, _ := strconv.Atoi(faulty)
	row := model.GetQueueWithProfileById(faultyInt)
	defer row.Close()

	owner := mux.Vars(r)["owner"]
	previous := mux.Vars(r)["previous"]

	row.Next()
	faultyProfile := rowToQueueProfile(row)

	var start = time.Now()
	o := ocr.New(faultyProfile.File, 0)

	o.Split()
	o.Process()
	o.CleanUp()

	model.UpdateProfile(faultyProfile.Profile.Id, o.Profile)

	processTime := time.Now().Sub(start).Nanoseconds() / 1e6
	model.SetQueueProcessed(faultyInt, processTime, faultyProfile.Profile.Id)

	http.Redirect(
		w, r,
		fmt.Sprintf("/admin/process/%s/%s/%s", owner, faulty, previous),
		302,
	)
}