Skip to content

Commit

Permalink
Make state setter in entity view model accessible to subclasses, prop…
Browse files Browse the repository at this point in the history
…erly handle cases when job processors set states rather than throwing exceptions and some cleanups
  • Loading branch information
beikov committed Oct 14, 2020
1 parent 0801ccf commit 933926f
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -533,10 +533,13 @@ public ActorRunResult call() throws Exception {
}
}

if (jobInstance.getState() != JobInstanceState.DONE) {
// We only mark the job as DONE when it was properly executed before and still has the NEW state
if (jobInstance.getState() == JobInstanceState.NEW) {
jobInstance.markDone(jobProcessingContext, lastProcessed);
jobContext.forEachJobInstanceListeners(new JobInstanceSuccessListenerConsumer(jobInstance, jobProcessingContext));
} else if (jobInstance.getState() == JobInstanceState.DONE) {
jobContext.forEachJobInstanceListeners(new JobInstanceSuccessListenerConsumer(jobInstance, jobProcessingContext));
}
jobContext.forEachJobInstanceListeners(new JobInstanceSuccessListenerConsumer(jobInstance, jobProcessingContext));
} catch (ExecutionException ex) {
Throwable t;
if (ex.getCause() instanceof CallableThrowable) {
Expand Down Expand Up @@ -728,10 +731,13 @@ public Object call() throws Exception {
}
}

if (jobInstance.getState() != JobInstanceState.DONE) {
// We only mark the job as DONE when it was properly executed before and still has the NEW state
if (jobInstance.getState() == JobInstanceState.NEW) {
jobInstance.markDone(jobProcessingContext, lastProcessed);
jobContext.forEachJobInstanceListeners(new JobInstanceSuccessListenerConsumer(jobInstance, jobProcessingContext));
} else if (jobInstance.getState() == JobInstanceState.DONE) {
jobContext.forEachJobInstanceListeners(new JobInstanceSuccessListenerConsumer(jobInstance, jobProcessingContext));
}
jobContext.forEachJobInstanceListeners(new JobInstanceSuccessListenerConsumer(jobInstance, jobProcessingContext));
return null;
} catch (Throwable t) {
jobInstance.markFailed(jobProcessingContext, t);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void markFailed(JobInstanceProcessingContext<?> jobProcessingContext, Thr
*
* @param state The state
*/
abstract void setState(JobInstanceState state);
protected abstract void setState(JobInstanceState state);

/**
* Sets the given defer count.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2018 - 2020 Blazebit.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.blazebit.job.view.model;

import java.io.Serializable;

/**
* A simple implementation of {@link JobConfigurationView} that can be overridden.
*
* @author Christian Beikov
* @since 1.0.0
*/
public abstract class DefaultJobConfigurationView extends JobConfigurationView {

@Override
protected Serializable getParameterSerializable() {
return null;
}

@Override
protected void setParameterSerializable(Serializable parameterSerializable) {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,4 @@ public interface IdHolderView<ID> extends Serializable {
@IdMapping
public ID getId();

/**
* Sets the id of the entity.
*
* @param id The id
*/
public void setId(ID id);

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.blazebit.job.jpa.model.ParameterSerializable;
import com.blazebit.job.jpa.model.TimeFrame;
import com.blazebit.persistence.view.EntityView;
import com.blazebit.persistence.view.PostLoad;
import com.blazebit.persistence.view.PreUpdate;

import java.io.Serializable;
Expand All @@ -42,14 +43,23 @@ public abstract class JobConfigurationView implements com.blazebit.job.JobConfig

private static final Serializable EMPTY = new Serializable() { };

private final DirtyMarkingSet<TimeFrame> executionTimeFrames;
private final DirtyMarkingMap<String, Serializable> parameters;
private DirtyMarkingSet<TimeFrame> executionTimeFrames;
private DirtyMarkingMap<String, Serializable> parameters;

/**
* Post Entity-View load lifecycle listener.
*/
@PostLoad
protected void postLoad() {
init((ParameterSerializable) getParameterSerializable());
}

/**
* Creates a new job configuration view.
*
* @param o The serializable parameter
*/
public JobConfigurationView() {
ParameterSerializable o = (ParameterSerializable) getParameterSerializable();
protected void init(ParameterSerializable o) {
if (o != null && o.getExecutionTimeFrames() != null) {
this.executionTimeFrames = new DirtyMarkingSet<>(o.getExecutionTimeFrames());
} else {
Expand Down

0 comments on commit 933926f

Please sign in to comment.