Process status
authorVásáry Dániel <vasary@elgekko.net>
Tue, 5 Dec 2023 22:53:15 +0000 (23:53 +0100)
committerVásáry Dániel <vasary@elgekko.net>
Tue, 5 Dec 2023 22:53:15 +0000 (23:53 +0100)
mc-vod-sync/mc-vod-sync-service/src/main/java/hu/user/mcvodsync/service/config/ScheduledTasks.java
mc-vod-sync/mc-vod-sync-service/src/main/java/hu/user/mcvodsync/service/event/ImportCompletedEvent.java
mc-vod-sync/mc-vod-sync-service/src/main/java/hu/user/mcvodsync/service/event/ImportStartedEvent.java
mc-vod-sync/mc-vod-sync-service/src/main/java/hu/user/mcvodsync/service/schedule/ScheduledImport.java
mc-vod-sync/mc-vod-sync-ui/src/main/java/hu/user/mcvodsync/ui/view/IndexViewModel.java
mc-vod-sync/mc-vod-sync-ui/src/main/resources/web/index.zul

index 6407ade8e26a868904deace3379c741cc5b991e3..6746aa9d9d20706b324539404bf232eaf19aa10f 100644 (file)
@@ -23,13 +23,6 @@ import java.time.Instant;
 @Component
 public class ScheduledTasks {
 
-    @Getter
-    private ImportSummary importSummary;
-
-    public ScheduledTasks() {
-        log.info("ScheduledTasks created");
-    }
-
     @Autowired
     private ServiceProperties serviceProperties;
 
@@ -45,6 +38,12 @@ public class ScheduledTasks {
     @Autowired
     private ScheduledSunriseChacker scheduledSunriseChacker;
 
+    @Getter
+    private ImportSummary importSummary;
+
+    @Getter
+    private String status;
+
     @PostConstruct
     public void scheduleTasks() {
         //new CronTrigger("0 0 4 1/1 * ? *")
@@ -76,6 +75,7 @@ public class ScheduledTasks {
     public void handleEvent(ImportStartedEvent evt) {
         log.info("ImportStartedEvent handle");
         importSummary = null;
+        status = String.format("Import from %s started", evt.getFileName());
     }
 
     @Async
@@ -83,5 +83,6 @@ public class ScheduledTasks {
     public void handleEvent(ImportCompletedEvent evt) {
         log.info("ImportCompletedEvent handle");
         importSummary = evt.getSummary();
+        status = "Import completed";
     }
 }
index 6e1a8f11692f76393d9c66de603584997322e9ca..1ef84d9520d7e8aabd93221035bbc5dce0591c0b 100644 (file)
@@ -11,7 +11,7 @@ public class ImportCompletedEvent extends ApplicationEvent {
 
     private final ImportSummary summary;
 
-    public ImportCompletedEvent(ImportSummary summary, Object source) {
+    public ImportCompletedEvent(Object source, ImportSummary summary) {
         super(source);
         this.summary = summary;
     }
index 0c8bc09c08dd3d5e411ce9e4c95b2e2a42886c20..0e931386c839432099d796fc55377b3d9dceb97c 100644 (file)
@@ -8,7 +8,10 @@ import org.springframework.context.ApplicationEvent;
 @Setter
 public class ImportStartedEvent extends ApplicationEvent {
 
-    public ImportStartedEvent(Object source) {
+    private String fileName;
+
+    public ImportStartedEvent(Object source, String fileName) {
         super(source);
+        this.fileName = fileName;
     }
 }
index 4ad3f22c29fbf2254056ca0322b8f9aeffcbc1e2..f268bffe183f0c5006ee547fe687da94f4421a5c 100644 (file)
@@ -27,18 +27,18 @@ public class ScheduledImport implements Runnable {
 
     @Override
     public void run() {
-        applicationEventPublisher.publishEvent(new ImportStartedEvent(this));
         ImportSummary summary = null;
         try {
-            log.info("ScheduledImport started");
             Optional<UploadFile> opUploadFile = uploadFileRepository.findFirstByOrderByCreatedDesc();
             if (opUploadFile.isPresent()) {
+                log.info("ScheduledImport started from {}", opUploadFile.get().getName());
+                applicationEventPublisher.publishEvent(new ImportStartedEvent(this, opUploadFile.get().getName()));
                 summary = vodXlsProcessor.process(opUploadFile.get().getName(), opUploadFile.get().getFile());
             }
         } catch (Exception e) {
             log.error("ScheduledImport error!", e);
         } finally {
-            applicationEventPublisher.publishEvent(new ImportCompletedEvent(summary, this));
+            applicationEventPublisher.publishEvent(new ImportCompletedEvent(this, summary));
             log.info("ScheduledImport finished");
         }
 
index 87b12f358113d969e0d6fed4869bbeee3c2635d0..27df65f801299a9cb67b333aaf52e59255b3ccec 100644 (file)
@@ -8,6 +8,7 @@ import hu.user.mcvodsync.db.repository.AssetRepository;
 import hu.user.mcvodsync.db.repository.AssetSyncRepository;
 import hu.user.mcvodsync.db.repository.PlaylistSyncRepository;
 import hu.user.mcvodsync.db.repository.UploadFileRepository;
+import hu.user.mcvodsync.service.config.ScheduledTasks;
 import hu.user.mcvodsync.ui.Constants;
 import hu.user.mcvodsync.ui.auth.CurrentProfile;
 import hu.user.mcvodsync.ui.session.SessionSettings;
@@ -54,6 +55,9 @@ public class IndexViewModel {
     @WireVariable
     private UploadFileRepository uploadFileRepository;
 
+    @WireVariable
+    private ScheduledTasks scheduledTasks;
+
     private String page;
 
     @Init
@@ -64,6 +68,11 @@ public class IndexViewModel {
         log.info("Init {}", path);
     }
 
+    @Command
+    public void onTimer() {
+        BindUtils.postNotifyChange(scheduledTasks, "status");
+    }
+
     @Command
     public void route(String path) {
         if (Constants.NAV_ROOT.equals(path))
index d569f89e5ef1744480665b99b5cb3e72de1fc96f..b863493f8e7ba1eb227c84c2bc9c00dfa186b451 100644 (file)
@@ -26,6 +26,7 @@
         }
     </script>
     <window vflex="true" viewModel="@id('vm') @init('hu.user.mcvodsync.ui.view.IndexViewModel')">
+        <timer delay="2000" onTimer="@command('onTimer')" repeats="true"/>
         <caption sclass="header" id="appHeader">
             <div style="display: block">
                 <div style="display: inline; float: left">
                 <include src="@load(vm.page)" hflex="true" vflex="true"/>
             </center>
             <south height="50px">
-                <hlayout>
-                    <div width="50px" height="50px" style="background: blue"></div>
-                </hlayout>
+                <hbox pack="end" align="center" hflex="true" vflex="true">
+                    <label style="font-size: 1.5em; padding-right: 20px; color: navy"
+                           value="@load(vm.scheduledTasks.status)"/>
+                </hbox>
             </south>
         </borderlayout>
     </window>