RE TS plugin to have continues tune auto-upload feature fix #1605
This commit is contained in:
parent
f6fad72b72
commit
78c2fb4bf4
|
@ -3,6 +3,8 @@ package com.rusefi.tune.xml;
|
|||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
|
||||
public class Bibliography {
|
||||
private String tuneComment = null;
|
||||
|
||||
@XmlAttribute
|
||||
public String getAuthor() {
|
||||
return "rusEFI";
|
||||
|
@ -10,7 +12,11 @@ public class Bibliography {
|
|||
|
||||
@XmlAttribute
|
||||
public String getTuneComment() {
|
||||
return "comments";
|
||||
return tuneComment;
|
||||
}
|
||||
|
||||
public void setTuneComment(String tuneComment) {
|
||||
this.tuneComment = tuneComment;
|
||||
}
|
||||
|
||||
@XmlAttribute
|
||||
|
|
|
@ -20,6 +20,8 @@ public class Msq {
|
|||
|
||||
public final VersionInfo versionInfo;
|
||||
|
||||
public Bibliography bibliography = new Bibliography();
|
||||
|
||||
public Msq() {
|
||||
versionInfo = new VersionInfo("rusEFI+2020");
|
||||
}
|
||||
|
@ -81,15 +83,6 @@ public class Msq {
|
|||
page.constant.add(new Constant(field.getName(), field.getUnits(), value));
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public Bibliography getBibliography() {
|
||||
return new Bibliography();
|
||||
}
|
||||
|
||||
public VersionInfo getVersionInfo() {
|
||||
return versionInfo;
|
||||
}
|
||||
|
||||
public Page findPage() {
|
||||
for (Page p : page) {
|
||||
Integer size = p.getSize();
|
||||
|
|
|
@ -25,8 +25,10 @@ public class XmlUtil {
|
|||
System.out.println(xmlWriter.toString());
|
||||
|
||||
System.out.println("Writing " + fileName);
|
||||
marshaller.marshal(instance, new FileWriter(fileName));
|
||||
FileWriter writer = new FileWriter(fileName);
|
||||
marshaller.marshal(instance, writer);
|
||||
System.out.println("Marshalling finished " + fileName);
|
||||
writer.close();
|
||||
}
|
||||
|
||||
public static <T> T readModel(Class<?> modelClass, String fileName) throws Exception {
|
||||
|
|
|
@ -15,7 +15,7 @@ import java.util.concurrent.LinkedBlockingDeque;
|
|||
|
||||
public class UploadQueue {
|
||||
public static final String OUTBOX_FOLDER = FileUtil.RUSEFI_SETTINGS_FOLDER + File.separator + "outbox";
|
||||
private static LinkedBlockingDeque<Msq> queue = new LinkedBlockingDeque<>(128);
|
||||
private static LinkedBlockingDeque<String> queue = new LinkedBlockingDeque<>(128);
|
||||
|
||||
private static boolean isStarted;
|
||||
|
||||
|
@ -39,8 +39,8 @@ public class UploadQueue {
|
|||
return;
|
||||
System.out.println(UploadQueue.class.getSimpleName() + " readOutbox " + file);
|
||||
try {
|
||||
Msq msg = Msq.readTune(OUTBOX_FOLDER + File.separator + file);
|
||||
queue.put(msg);
|
||||
String fileName = OUTBOX_FOLDER + File.separator + file;
|
||||
queue.put(fileName);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -50,30 +50,23 @@ public class UploadQueue {
|
|||
|
||||
private static void uploadLoop() throws InterruptedException {
|
||||
while (true) {
|
||||
Msq msq = queue.take();
|
||||
String fileName = queue.take();
|
||||
|
||||
new File(OUTBOX_FOLDER).mkdirs();
|
||||
String fileName = OUTBOX_FOLDER + File.separator + System.currentTimeMillis() + ".msq";
|
||||
try {
|
||||
msq.writeXmlFile(fileName);
|
||||
UploadResult result = Online.upload(new File(fileName), AuthTokenPanel.getAuthToken());
|
||||
System.out.println("isError " + result.isError());
|
||||
System.out.println("first " + result.getFirstMessage());
|
||||
if (result.isError() && result.getFirstMessage().contains("This file already exists")) {
|
||||
System.out.println(UploadQueue.class.getSimpleName() + " No need to re-try this one");
|
||||
delete(fileName);
|
||||
// do not retry this error
|
||||
continue;
|
||||
}
|
||||
if (result.isError()) {
|
||||
System.out.println(UploadQueue.class.getSimpleName() + " Re-queueing " + msq);
|
||||
queue.put(msq);
|
||||
continue;
|
||||
}
|
||||
UploadResult result = Online.upload(new File(fileName), AuthTokenPanel.getAuthToken());
|
||||
System.out.println("isError " + result.isError());
|
||||
System.out.println("first " + result.getFirstMessage());
|
||||
if (result.isError() && result.getFirstMessage().contains("This file already exists")) {
|
||||
System.out.println(UploadQueue.class.getSimpleName() + " No need to re-try this one");
|
||||
delete(fileName);
|
||||
} catch (JAXBException | IOException e) {
|
||||
e.printStackTrace();
|
||||
// do not retry this error
|
||||
continue;
|
||||
}
|
||||
if (result.isError()) {
|
||||
System.out.println(UploadQueue.class.getSimpleName() + " Re-queueing " + fileName);
|
||||
queue.put(fileName);
|
||||
continue;
|
||||
}
|
||||
delete(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,9 +82,13 @@ public class UploadQueue {
|
|||
return;
|
||||
}
|
||||
Msq msq = TuneUploder.grabTune(controllerAccess, configurationName);
|
||||
msq.bibliography.setTuneComment("Auto-saved");
|
||||
try {
|
||||
queue.put(msq);
|
||||
} catch (InterruptedException e) {
|
||||
new File(OUTBOX_FOLDER).mkdirs();
|
||||
String fileName = OUTBOX_FOLDER + File.separator + System.currentTimeMillis() + ".msq";
|
||||
msq.writeXmlFile(fileName);
|
||||
queue.put(fileName);
|
||||
} catch (InterruptedException | JAXBException | IOException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue