Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JBPM-10176] Detect creation of timers for notifications #2283

Merged
merged 1 commit into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ public static class ProcessJobContext implements JobContext {
private JobHandle jobHandle;
private Long sessionId;

private boolean newTimer;
private boolean isNew;

public ProcessJobContext(final TimerInstance timer, final Trigger trigger, final Long processInstanceId,
final InternalKnowledgeRuntime kruntime) {
Expand All @@ -408,17 +408,17 @@ public ProcessJobContext(final TimerInstance timer, final Trigger trigger, final
this.processInstanceId = processInstanceId;
this.kruntime = kruntime;
this.sessionId = timer.getSessionId();
this.newTimer = true;
this.isNew = true;
}

public ProcessJobContext(final TimerInstance timer, final Trigger trigger, final Long processInstanceId,
final InternalKnowledgeRuntime kruntime, boolean newTimer) {
final InternalKnowledgeRuntime kruntime, boolean isNew) {
this.timer = timer;
this.trigger = trigger;
this.processInstanceId = processInstanceId;
this.kruntime = kruntime;
this.sessionId = timer.getSessionId();
this.newTimer = newTimer;
this.isNew = isNew;
}

public Long getProcessInstanceId() {
Expand Down Expand Up @@ -457,9 +457,10 @@ public void setKnowledgeRuntime(InternalKnowledgeRuntime kruntime) {
public InternalWorkingMemory getWorkingMemory() {
return kruntime instanceof InternalWorkingMemory ? (InternalWorkingMemory)kruntime : null;
}

public boolean isNewTimer() {
return newTimer;

@Override
public boolean isNew() {
return isNew;
}
}

Expand Down Expand Up @@ -493,7 +494,7 @@ public void setParamaeters(Map<String, Object> paramaeters) {
}

@Override
public boolean isNewTimer() {
public boolean isNew() {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,15 @@ public void setPersistenceContext(TaskPersistenceContext persistenceContext) {
this.persistenceContext = persistenceContext;
}

public void scheduleNew(long taskId, long deadlineId, long delay, DeadlineType type) {
schedule(taskId, deadlineId, delay, type, true);
}

public void schedule(long taskId, long deadlineId, long delay, DeadlineType type) {
schedule(taskId, deadlineId, delay, type, false);
}

public void schedule(long taskId, long deadlineId, long delay, DeadlineType type, boolean isNew) {
Task task = persistenceContext.findTask(taskId);
String deploymentId = task.getTaskData().getDeploymentId();

Expand All @@ -99,7 +106,7 @@ public void schedule(long taskId, long deadlineId, long delay, DeadlineType type
0,
null,
null ) ;
JobHandle handle = timerService.scheduleJob(deadlineJob, new TaskDeadlineJobContext(deadlineJob.getId(), task.getTaskData().getProcessInstanceId(), deploymentId), trigger);
JobHandle handle = timerService.scheduleJob(deadlineJob, new TaskDeadlineJobContext(deadlineJob.getId(), task.getTaskData().getProcessInstanceId(), deploymentId, isNew), trigger);
jobHandles.put(deadlineJob.getId(), handle);

} else {
Expand Down Expand Up @@ -363,13 +370,24 @@ private static class TaskDeadlineJobContext implements NamedJobContext {
private String jobName;
private Long processInstanceId;
private String deploymentId;
private boolean isNew;

public TaskDeadlineJobContext(String jobName, Long processInstanceId, String deploymentId) {
this(jobName, processInstanceId, deploymentId, false);
}

public TaskDeadlineJobContext(String jobName, Long processInstanceId, String deploymentId, boolean isNew) {
this.jobName = jobName;
this.processInstanceId = processInstanceId;
this.deploymentId = deploymentId;
this.isNew = isNew;
}

@Override
public boolean isNew() {
return isNew;
}

@Override
public void setJobHandle(JobHandle jobHandle) {
this.jobHandle = jobHandle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public static void scheduleDeadlines(final List<? extends Deadline> deadlines, f
for (Deadline deadline : deadlines) {
if (Boolean.FALSE.equals(deadline.isEscalated())) {
Date date = deadline.getDate();
deadlineService.schedule(taskId, deadline.getId(), date.getTime() - now, type);
deadlineService.scheduleNew(taskId, deadline.getId(), date.getTime() - now, type);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
import org.jbpm.process.core.timer.impl.DelegateSchedulerServiceInterceptor;
import org.jbpm.process.core.timer.impl.GlobalTimerService;
import org.jbpm.process.core.timer.impl.GlobalTimerService.GlobalJobHandle;
import org.jbpm.process.instance.timer.TimerManager.ProcessJobContext;
import org.jbpm.runtime.manager.impl.jpa.EntityManagerFactoryManager;
import org.jbpm.runtime.manager.impl.jpa.TimerMappingInfo;
import org.kie.internal.runtime.manager.InternalRuntimeManager;
Expand Down Expand Up @@ -77,7 +76,7 @@ public JobHandle scheduleJob(Job job, JobContext ctx, Trigger trigger) {
TimerJobInstance jobInstance = null;
// check if given timer job is marked as new timer meaning it was never scheduled before,
// if so skip the check by timer name as it has no way to exist
if (!isNewTimer(ctx)) {
if (!ctx.isNew()) {
jobInstance = getTimerJobInstance(jobName);
if (jobInstance == null) {
jobInstance = scheduler.getTimerByName(jobName);
Expand Down Expand Up @@ -265,9 +264,4 @@ public boolean isValid(GlobalJobHandle jobHandle) {
protected String getJobName(JobContext ctx, long id) {
return JobNameHelper.getJobName(ctx, id);
}

private boolean isNewTimer(JobContext ctx) {
return ctx instanceof ProcessJobContext && ((ProcessJobContext) ctx).isNewTimer();
}

}
Loading