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

Prosesstask kan annoteres med default prioritet #629

Merged
merged 1 commit into from
Jun 4, 2024
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 @@ -50,6 +50,12 @@
*/
String value();

/**
* Standard prioritet for task type
*/
@Nonbinding
int prioritet() default 1;

/**
* Cron-expression to schedule next instance of a repeating task.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ public class ProsessTaskData implements ProsessTaskInfo {
}

public static ProsessTaskData forProsessTask(Class<? extends ProsessTaskHandler> clazz) {
return new ProsessTaskData(TaskType.forProsessTask(clazz));
var prosessTaskData = new ProsessTaskData(TaskType.forProsessTask(clazz));
prosessTaskData.setPrioritet(TaskType.prioritet(clazz));
return prosessTaskData;
}

public static ProsessTaskData forTaskType(TaskType taskType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ private ProsessTaskDataBuilder(TaskType taskType) {
}

public static ProsessTaskDataBuilder forProsessTask(Class<? extends ProsessTaskHandler> clazz) {
return new ProsessTaskDataBuilder(TaskType.forProsessTask(clazz));
return new ProsessTaskDataBuilder(TaskType.forProsessTask(clazz)).medPrioritet(TaskType.prioritet(clazz));
}

public static ProsessTaskDataBuilder forTaskType(TaskType taskType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ public record TaskType(String value) {
public static TaskType forProsessTask(Class<? extends ProsessTaskHandler> clazz) {
return new TaskType(clazz.getAnnotation(ProsessTask.class).value());
}

public static int prioritet(Class<? extends ProsessTaskHandler> clazz) {
return clazz.getAnnotation(ProsessTask.class).prioritet();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
import java.lang.annotation.Annotation;
import java.util.Set;

import jakarta.enterprise.context.Dependent;
import jakarta.enterprise.inject.spi.CDI;
import jakarta.enterprise.util.AnnotationLiteral;

import org.jboss.weld.interceptor.util.proxy.TargetInstanceProxy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import jakarta.enterprise.context.Dependent;
import jakarta.enterprise.inject.spi.CDI;
import jakarta.enterprise.util.AnnotationLiteral;
import no.nav.vedtak.felles.prosesstask.api.ProsessTask;
import no.nav.vedtak.felles.prosesstask.api.ProsessTaskData;
import no.nav.vedtak.felles.prosesstask.api.ProsessTaskHandler;
Expand Down Expand Up @@ -111,6 +110,11 @@ public String value() {
return taskType;
}

@Override
public int prioritet() {
return 1;
}

@Override
public String cronExpression() {
return "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ProsessTaskTjenesteImplTest {

private ProsessTaskTjeneste prosessTaskTjeneste;

@ProsessTask(TASK_TYPE_NAME_OPPR)
@ProsessTask(value = TASK_TYPE_NAME_OPPR, prioritet = 3)
private static class DummyHandlerOpprett implements ProsessTaskHandler {
@Override
public void doTask(ProsessTaskData prosessTaskData) {
Expand All @@ -61,6 +61,8 @@ void skal_opprette_task() {
.medProperty(REQUIRED_PROPERTY, "Verdi")
.build();

assertThat(ptd.getPriority()).isEqualTo(TaskType.prioritet(DummyHandlerOpprett.class));

when(prosessTaskRepositoryMock.lagre(any(ProsessTaskData.class))).thenReturn("gruppe-id");

prosessTaskTjeneste.lagreValidert(ptd);
Expand All @@ -72,6 +74,7 @@ void skal_opprette_task() {

verify(prosessTaskRepositoryMock, times(1)).lagre(any(ProsessTaskGruppe.class));
assertThat(dataTilPersistering.getTasks().get(0).task().taskType()).isEqualTo(TaskType.forProsessTask(DummyHandlerOpprett.class));
assertThat(dataTilPersistering.getTasks().get(0).task().getPriority()).isEqualTo(TaskType.prioritet(DummyHandlerOpprett.class));
}

@Test
Expand Down