func addNameTag(writer http.ResponseWriter, request *http.Request) { request.ParseForm() nameTag := new(data.NameTag) decoder := schema.NewDecoder() err := decoder.Decode(nameTag, request.Form) fmt.Println(request.Form) if check(err, 400, &writer) { return } if nameTag.Name == "" { log.Println(errors.New("No Name Provided")) http.Error(writer, http.StatusText(400), 400) return } nameTag.Id = uuid.NewV1() nameTag.State = "Waiting" nameTagQueue.Add(*nameTag, &configImpl) json, err := json.MarshalIndent(nameTagQueue.Queue, "", " ") if check(err, 500, &writer) { return } writer.Write(json) }
func run(interval time.Duration, nameTagQueue *data.NameTagQueue, printerQueue *data.PrinterQueue, config *config.Config) { fmt.Println("Print Server Started") Timer = time.NewTicker(interval * time.Second) for { select { case <-Timer.C: printer := printerQueue.GetNext() if printer == nil { continue } var nameTag *data.NameTag getNew: if printer.NameTag != nil && printer.NameTag.Error == false { fmt.Printf("%v\n", printer.NameTag) tag, err := nameTagQueue.Find(printer.NameTag.Id, config) if err != nil { printer.NameTag.Error = true goto getNew } nameTag = tag } else { nameTag = nameTagQueue.GetNext() if nameTag == nil { continue } printer.NameTag = nameTag } nameTag.State = "Assigned to printer" if nameTag.Stl == "" { nameTag.State = "Rendering STL" err := service.Export(nameTag, config) if err != nil { fmt.Println(err) nameTag.Error = true nameTag.State = "Has Error" goto save } } if nameTag.Gcode == "" { nameTag.State = "Slicing" err := service.Slice(nameTag, printer, config) if err != nil { fmt.Println(err) nameTag.Error = true nameTag.State = "Has Error" goto save } } if nameTag.Printing == false && printer.Printing == false { nameTag.State = "Uploading" err := service.Upload(nameTag, printer, config) if err != nil { log.Println(err) printer.Active = false goto save } printer.Printing = true nameTag.Printing = true nameTag.State = "Printing" } save: printerQueue.Save(config) nameTagQueue.Save(config) config.DebugLog("Finnished Loop") case <-Quit: Timer.Stop() return } } }