Use a NonPersistedAsyncJobCallback for cases where it doesn't need to be persisted to state provider

This commit is contained in:
2024-04-06 20:23:58 -05:00
parent 9ab5a8b305
commit 5520111836
4 changed files with 102 additions and 2 deletions

View File

@ -31,6 +31,7 @@ import java.io.Serializable;
*******************************************************************************/ *******************************************************************************/
public class AsyncJobStatus implements Serializable public class AsyncJobStatus implements Serializable
{ {
private String jobName;
private AsyncJobState state; private AsyncJobState state;
private String message; private String message;
private Integer current; private Integer current;
@ -187,4 +188,36 @@ public class AsyncJobStatus implements Serializable
{ {
this.cancelRequested = cancelRequested; 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);
}
} }

View File

@ -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 <https://www.gnu.org/licenses/>.
*/
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());
}
}

View File

@ -26,6 +26,7 @@ import java.util.UUID;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import com.kingsrook.qqq.backend.core.actions.async.AsyncJobCallback; 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.AsyncJobStatus;
import com.kingsrook.qqq.backend.core.actions.async.NonPersistedAsyncJobCallback;
import com.kingsrook.qqq.backend.core.context.QContext; import com.kingsrook.qqq.backend.core.context.QContext;
import com.kingsrook.qqq.backend.core.exceptions.QInstanceValidationException; import com.kingsrook.qqq.backend.core.exceptions.QInstanceValidationException;
import com.kingsrook.qqq.backend.core.instances.QInstanceValidator; 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. // // 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; return asyncJobCallback;
} }

View File

@ -30,6 +30,7 @@ import java.util.Map;
import java.util.UUID; import java.util.UUID;
import com.kingsrook.qqq.backend.core.actions.async.AsyncJobCallback; 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.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.actions.processes.QProcessCallback;
import com.kingsrook.qqq.backend.core.context.QContext; import com.kingsrook.qqq.backend.core.context.QContext;
import com.kingsrook.qqq.backend.core.model.actions.AbstractActionInput; 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... // // 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); return (asyncJobCallback);
} }