Add external program timeout as station setting
Leaving it without a UI implementation for now
This commit is contained in:
		| @@ -270,8 +270,8 @@ public class Main extends Application { | ||||
|             switch (loadedStation.getMessageMethod()) { | ||||
|                 case StationSettings.MessageMethod.EXTERNAL_PROGRAM: | ||||
|                     Process process = new ProcessBuilder(loadedStation.getExternalProgramCommand(), nextMessagePath.toString()).start(); | ||||
|                     // TODO: make timeout a setting | ||||
|                     if (!process.waitFor(5, TimeUnit.SECONDS)) { | ||||
|  | ||||
|                     if (!process.waitFor(loadedStation.getExternalProgramTimeout().getSeconds(), TimeUnit.SECONDS)) { | ||||
|                         throw new StationRunException("Timeout while running external program " + loadedStation.getExternalProgramCommand()); | ||||
|                     } | ||||
|  | ||||
|   | ||||
| @@ -100,6 +100,7 @@ public class MainSettings { | ||||
|         XmlMapper xmlMapper = new XmlMapper(); | ||||
|         xmlMapper.registerModule(new JavaTimeModule()); | ||||
|         xmlMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); | ||||
|         xmlMapper.configure(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS, false); | ||||
|         xmlMapper.enable(SerializationFeature.INDENT_OUTPUT); | ||||
|         try { | ||||
|             Path filePath = getSettingsFilePath(); | ||||
|   | ||||
| @@ -10,6 +10,7 @@ import java.nio.file.Path; | ||||
| import java.nio.file.Paths; | ||||
| import java.nio.file.SimpleFileVisitor; | ||||
| import java.security.SecureRandom; | ||||
| import java.time.Duration; | ||||
| import java.time.LocalDate; | ||||
| import java.time.LocalDateTime; | ||||
| import java.time.ZonedDateTime; | ||||
| @@ -27,6 +28,7 @@ public class StationSettings { | ||||
|     private String address; | ||||
|     private int digitsPerGroup; | ||||
|     private String externalProgramCommand; | ||||
|     private Duration externalProgramTimeout; | ||||
|     private boolean manageScheduleExternally; | ||||
|     private int messageLength; | ||||
|     private MessageMethod messageMethod; | ||||
| @@ -53,6 +55,7 @@ public class StationSettings { | ||||
|         prefixes = new ArrayList<String>(); | ||||
|         digitsPerGroup = 4; | ||||
|         messageLength = 100; | ||||
|         externalProgramTimeout = Duration.ofSeconds(5); | ||||
|         messageMethod = MessageMethod.SFTP; | ||||
|         messagePeriod = MessagePeriod.DAILY; | ||||
|         scheduleStart = ZonedDateTime.now(); | ||||
| @@ -62,6 +65,7 @@ public class StationSettings { | ||||
|         name = newName; | ||||
|         prefixes = new ArrayList<String>(); | ||||
|         digitsPerGroup = 4; | ||||
|         externalProgramTimeout = Duration.ofSeconds(5); | ||||
|         messageLength = 100; | ||||
|         messageMethod = MessageMethod.SFTP; | ||||
|         messagePeriod = MessagePeriod.DAILY; | ||||
| @@ -250,6 +254,14 @@ public class StationSettings { | ||||
|         externalProgramCommand = newExternalProgramCommand; | ||||
|     } | ||||
|  | ||||
|     public Duration getExternalProgramTimeout() { | ||||
|         return externalProgramTimeout; | ||||
|     } | ||||
|  | ||||
|     public void setExternalProgramTimeout(Duration newExternalProgramTimeout) { | ||||
|         externalProgramTimeout = newExternalProgramTimeout; | ||||
|     } | ||||
|  | ||||
|     public boolean getManageScheduleExternally() { | ||||
|         return manageScheduleExternally; | ||||
|     } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user