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

Changing chaningTask to hold data. #11

Closed
wants to merge 2 commits into from
Closed
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
@@ -1,6 +1,6 @@
package com.github.bekk.dbscheduleruibackend.example;

import com.github.bekk.dbscheduleruibackend.model.TaskData;
import com.github.bekk.dbscheduleruibackend.model.TestObject;
import com.github.kagkarlsson.scheduler.SchedulerClient;
import com.github.kagkarlsson.scheduler.task.helper.OneTimeTask;
import com.github.kagkarlsson.scheduler.task.helper.Tasks;
Expand All @@ -9,21 +9,33 @@

public class ChainTask {

public static OneTimeTask<TaskData> chainTaskStepOne() {
return Tasks.oneTime("chained-onetime-task-step1", TaskData.class).
public static OneTimeTask<TestObject> chainTaskStepOne() {
return Tasks.oneTime("chained-onetime-task-step1", TestObject.class).
execute((inst, ctx) ->{
final SchedulerClient client = ctx.getSchedulerClient();
System.out.println("Executed chained onetime task step 1: " + inst.getTaskName()+ " " + inst.getId());
client.schedule(chainTaskStepTwo().instance(inst.getId()), Instant.now());
try {
sleep(500);
final SchedulerClient client = ctx.getSchedulerClient();
System.out.println("Executed chained onetime task step 1: " + inst.getTaskName()+ " " + inst.getId());
TestObject data = inst.getData();
data.setId(data.getId()+1);
client.schedule(chainTaskStepTwo().instance(inst.getId(), data), Instant.now());
} catch (InterruptedException e) {
throw new RuntimeException(e);
}

});
}

public static OneTimeTask<TaskData> chainTaskStepTwo(){
return Tasks.oneTime("chained-onetime-task-step2", TaskData.class).
public static OneTimeTask<TestObject> chainTaskStepTwo(){
return Tasks.oneTime("chained-onetime-task-step2", TestObject.class).
execute((inst, ctx) -> {
try {
sleep(5000);
sleep(500);
final SchedulerClient client = ctx.getSchedulerClient();
System.out.println("Executed chained onetime task step 2: " + inst.getTaskName() + " " + inst.getId());
TestObject data = inst.getData();
data.setId(data.getId()+1);
client.schedule(chainTaskStepOne().instance(inst.getId(),data), Instant.now());
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.bekk.dbscheduleruibackend.example;

import com.github.bekk.dbscheduleruibackend.model.TaskData;
import com.github.bekk.dbscheduleruibackend.model.TestObject;
import com.github.kagkarlsson.scheduler.task.Task;
import com.github.kagkarlsson.scheduler.task.TaskInstance;

Expand Down Expand Up @@ -28,8 +29,7 @@ public static List<TaskInstance<?>> getAllKnownTaskInstances() {
return List.of(
OneTimeTaskExample.getExample().instance("1", new TaskData(1, "test data")),
RecurringTaskExample.getExample().instance("2"),
ChainTask.chainTaskStepOne().instance("3"),
ChainTask.chainTaskStepTwo().instance("4"),
ChainTask.chainTaskStepOne().instance("3", new TestObject("Ole Nordman", 3, "[email protected]")),
LongRunningTask.runLongRunningTask().instance("5"),
FailingTask.runOneTimeFailing().instance("6"),
FailingTask.runRecurringFailing().instance("7"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.github.bekk.dbscheduleruibackend.model;

import java.io.Serializable;

public class TestObject implements Serializable {
private String name;
private int id;
private String email;

public String getName() {
return name;
}
public TestObject(String initialName, int id, String email) {
this.id = id;
this.name = initialName;
this.email = email;

}

public void setName(String name) {
this.name = name;
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

import com.github.bekk.dbscheduleruibackend.example.*;
import com.github.bekk.dbscheduleruibackend.example.OneTimeTaskExample;
import com.github.bekk.dbscheduleruibackend.model.TaskModel;
import com.github.bekk.dbscheduleruibackend.model.TaskRequestParams;
import com.github.bekk.dbscheduleruibackend.model.GetTasksResponse;
import com.github.bekk.dbscheduleruibackend.model.TaskData;
import com.github.bekk.dbscheduleruibackend.model.TaskType;
import com.github.bekk.dbscheduleruibackend.model.*;
import com.github.bekk.dbscheduleruibackend.util.mapper.TaskMapper;
import com.github.kagkarlsson.scheduler.ScheduledExecution;
import com.github.kagkarlsson.scheduler.Scheduler;
Expand Down Expand Up @@ -78,7 +74,7 @@ public void runRecurringTask() {
public void runChainTask() {
long randomUUID = UUID.randomUUID().getMostSignificantBits() & Long.MAX_VALUE;
System.out.println("Chain test");
scheduler.schedule(ChainTask.chainTaskStepOne().instance(Long.toString(randomUUID), new TaskData(randomUUID, "test")), Instant.now().plusSeconds(1));
scheduler.schedule(ChainTask.chainTaskStepOne().instance(Long.toString(randomUUID), new TestObject("Ole Nordman", 3, "[email protected]")), Instant.now().plusSeconds(100));
}

public void runAllTasks(){
Expand Down