From 55201118364d86d923ed4e6f1d4e0bd7fcaa033c Mon Sep 17 00:00:00 2001 From: Darin Kelkhoff Date: Sat, 6 Apr 2024 20:23:58 -0500 Subject: [PATCH] Use a NonPersistedAsyncJobCallback for cases where it doesn't need to be persisted to state provider --- .../core/actions/async/AsyncJobStatus.java | 33 ++++++++++ .../async/NonPersistedAsyncJobCallback.java | 65 +++++++++++++++++++ .../model/actions/AbstractActionInput.java | 3 +- .../processes/RunBackendStepInput.java | 3 +- 4 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/async/NonPersistedAsyncJobCallback.java diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/async/AsyncJobStatus.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/async/AsyncJobStatus.java index 3ec54516..c5cf95f3 100644 --- a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/async/AsyncJobStatus.java +++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/async/AsyncJobStatus.java @@ -31,6 +31,7 @@ import java.io.Serializable; *******************************************************************************/ public class AsyncJobStatus implements Serializable { + private String jobName; private AsyncJobState state; private String message; private Integer current; @@ -187,4 +188,36 @@ public class AsyncJobStatus implements Serializable { this.cancelRequested = cancelRequested; } + + + + /******************************************************************************* + ** Getter for jobName + *******************************************************************************/ + public String getJobName() + { + return (this.jobName); + } + + + + /******************************************************************************* + ** Setter for jobName + *******************************************************************************/ + public void setJobName(String jobName) + { + this.jobName = jobName; + } + + + + /******************************************************************************* + ** Fluent setter for jobName + *******************************************************************************/ + public AsyncJobStatus withJobName(String jobName) + { + this.jobName = jobName; + return (this); + } + } diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/async/NonPersistedAsyncJobCallback.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/async/NonPersistedAsyncJobCallback.java new file mode 100644 index 00000000..0e413a38 --- /dev/null +++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/actions/async/NonPersistedAsyncJobCallback.java @@ -0,0 +1,65 @@ +/* + * QQQ - Low-code Application Framework for Engineers. + * Copyright (C) 2021-2024. Kingsrook, LLC + * 651 N Broad St Ste 205 # 6917 | Middletown DE 19709 | United States + * contact@kingsrook.com + * https://github.com/Kingsrook/ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package com.kingsrook.qqq.backend.core.actions.async; + + +import java.util.UUID; +import com.kingsrook.qqq.backend.core.logging.QLogger; + + +/******************************************************************************* + ** subclass designed to be used when we want there to be an instance (so code + ** doesn't have to all be null-tolerant), but there's no one who will ever be + ** reading the status data, so we don't need to store the object in a + ** state provider. + *******************************************************************************/ +public class NonPersistedAsyncJobCallback extends AsyncJobCallback +{ + private static final QLogger LOG = QLogger.getLogger(NonPersistedAsyncJobCallback.class); + private final AsyncJobStatus asyncJobStatus; + + + + /******************************************************************************* + ** + *******************************************************************************/ + public NonPersistedAsyncJobCallback(UUID jobUUID, AsyncJobStatus asyncJobStatus) + { + super(jobUUID, asyncJobStatus); + this.asyncJobStatus = asyncJobStatus; + } + + + + /******************************************************************************* + ** + *******************************************************************************/ + @Override + protected void storeUpdatedStatus() + { + /////////////////////////////////////////////////////////// + // todo - downgrade or remove this before merging to dev // + /////////////////////////////////////////////////////////// + LOG.info("Not persisting status from a NonPersistedAsyncJobCallback: " + asyncJobStatus.getJobName() + " / " + asyncJobStatus.getMessage()); + } + +} diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/actions/AbstractActionInput.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/actions/AbstractActionInput.java index 429948d4..3c98715b 100644 --- a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/actions/AbstractActionInput.java +++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/actions/AbstractActionInput.java @@ -26,6 +26,7 @@ import java.util.UUID; import com.fasterxml.jackson.annotation.JsonIgnore; import com.kingsrook.qqq.backend.core.actions.async.AsyncJobCallback; import com.kingsrook.qqq.backend.core.actions.async.AsyncJobStatus; +import com.kingsrook.qqq.backend.core.actions.async.NonPersistedAsyncJobCallback; import com.kingsrook.qqq.backend.core.context.QContext; import com.kingsrook.qqq.backend.core.exceptions.QInstanceValidationException; import com.kingsrook.qqq.backend.core.instances.QInstanceValidator; @@ -139,7 +140,7 @@ public class AbstractActionInput //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // don't return null here (too easy to NPE). instead, if someone wants one of these, create one and give it to them. // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - asyncJobCallback = new AsyncJobCallback(UUID.randomUUID(), new AsyncJobStatus()); + asyncJobCallback = new NonPersistedAsyncJobCallback(UUID.randomUUID(), new AsyncJobStatus().withJobName(getClass().getSimpleName())); } return asyncJobCallback; } diff --git a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/actions/processes/RunBackendStepInput.java b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/actions/processes/RunBackendStepInput.java index 18d63f75..bfaad833 100644 --- a/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/actions/processes/RunBackendStepInput.java +++ b/qqq-backend-core/src/main/java/com/kingsrook/qqq/backend/core/model/actions/processes/RunBackendStepInput.java @@ -30,6 +30,7 @@ import java.util.Map; import java.util.UUID; import com.kingsrook.qqq.backend.core.actions.async.AsyncJobCallback; import com.kingsrook.qqq.backend.core.actions.async.AsyncJobStatus; +import com.kingsrook.qqq.backend.core.actions.async.NonPersistedAsyncJobCallback; import com.kingsrook.qqq.backend.core.actions.processes.QProcessCallback; import com.kingsrook.qqq.backend.core.context.QContext; import com.kingsrook.qqq.backend.core.model.actions.AbstractActionInput; @@ -450,7 +451,7 @@ public class RunBackendStepInput extends AbstractActionInput ///////////////////////////////////////////////////////////////////////// // avoid NPE in case we didn't have one of these! create a new one... // ///////////////////////////////////////////////////////////////////////// - asyncJobCallback = new AsyncJobCallback(UUID.randomUUID(), new AsyncJobStatus()); + asyncJobCallback = new NonPersistedAsyncJobCallback(UUID.randomUUID(), new AsyncJobStatus().withJobName(processName + "." + stepName)); } return (asyncJobCallback); }