Пример #1
0
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,
	)
}
Пример #2
0
func ProcessQueue() {
	ocr.InitConfig()
	for {
		<-Queue
		log.Println("Queue: Processing.")

		queue := model.GetPendingQueues()

		for queue.Next() {
			var start = time.Now()

			var id, user_id, timestamp int
			var file string
			var processed bool
			var ocrProfile int

			if err := queue.Scan(&id, &user_id, &timestamp, &file, &processed, &ocrProfile); err != nil {
				log.Fatal(err)
			}

			o := ocr.New(file, ocrProfile)

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

			p := o.Profile
			profileId := model.InsertProfile(user_id, timestamp, p)

			processTime := time.Now().Sub(start).Nanoseconds() / 1e6
			model.SetQueueProcessed(id, processTime, profileId)

			log.Printf("Queue: Entry processed in %dms: %s L%d %dAP", processTime, p.Nick, p.Level, p.AP)
		}

		log.Println("Queue: Done.")

		queue.Close()
	}
}