You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@causeway.apache.org by da...@apache.org on 2023/09/26 21:48:57 UTC

[causeway] 01/01: CAUSEWAY-3602 : adds the ability to pause/resume the RunBackgroundCommandsJob

This is an automated email from the ASF dual-hosted git repository.

danhaywood pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/causeway.git

commit f8bb2d10a9b1c55025aa3cedb4886196aebd2b1f
Author: danhaywood <da...@haywood-associates.co.uk>
AuthorDate: Tue Sep 26 22:48:50 2023 +0100

    CAUSEWAY-3602 : adds the ability to pause/resume the RunBackgroundCommandsJob
---
 .../applib/job/RunBackgroundCommandsJob.java       | 25 ++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/extensions/core/commandlog/applib/src/main/java/org/apache/causeway/extensions/commandlog/applib/job/RunBackgroundCommandsJob.java b/extensions/core/commandlog/applib/src/main/java/org/apache/causeway/extensions/commandlog/applib/job/RunBackgroundCommandsJob.java
index ca5792a83d..ed55916c44 100644
--- a/extensions/core/commandlog/applib/src/main/java/org/apache/causeway/extensions/commandlog/applib/job/RunBackgroundCommandsJob.java
+++ b/extensions/core/commandlog/applib/src/main/java/org/apache/causeway/extensions/commandlog/applib/job/RunBackgroundCommandsJob.java
@@ -25,6 +25,8 @@ import java.util.stream.Collectors;
 
 import javax.inject.Inject;
 
+import org.apache.causeway.applib.annotation.Programmatic;
+
 import org.quartz.DisallowConcurrentExecution;
 import org.quartz.Job;
 import org.quartz.JobExecutionContext;
@@ -44,6 +46,7 @@ import org.apache.causeway.extensions.commandlog.applib.dom.CommandLogEntry;
 import org.apache.causeway.extensions.commandlog.applib.dom.CommandLogEntryRepository;
 import org.apache.causeway.schema.cmd.v2.CommandDto;
 
+import lombok.Getter;
 import lombok.val;
 import lombok.extern.log4j.Log4j2;
 
@@ -66,9 +69,31 @@ public class RunBackgroundCommandsJob implements Job {
     @Inject CommandLogEntryRepository<? extends CommandLogEntry> commandLogEntryRepository;
     @Inject CommandExecutorService commandExecutorService;
 
+    public enum State {
+        RUNNING,
+        PAUSED
+    }
+
+    @Getter
+    private State state = State.RUNNING;
+
+    @Programmatic
+    public void pause() {
+        state = State.PAUSED;
+    }
+    @Programmatic
+    public void resume() {
+        state = State.RUNNING;
+    }
+
     @Override
     public void execute(final JobExecutionContext quartzContext) {
 
+        if (state == State.PAUSED) {
+            log.debug("state is " + state);
+            return;
+        }
+
         UserMemento user = UserMemento.ofNameAndRoleNames("scheduler_user", "admin_role");
         InteractionContext interactionContext = InteractionContext.builder().user(user).build();