Skip to content

Commit

Permalink
Fixed task data to parse properly to list
Browse files Browse the repository at this point in the history
  • Loading branch information
vegarrsm committed Sep 1, 2023
1 parent 6132ce8 commit 5d3c608
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 10 deletions.
1 change: 1 addition & 0 deletions db-scheduler-ui-frontend/src/assets/icons/RepeatIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ export const RepeatIcon = createIcon({
strokeWidth="32"
/>
</svg>
),
});
2 changes: 1 addition & 1 deletion db-scheduler-ui-frontend/src/components/TaskCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const TaskCard: React.FC<TaskCardProps> = ({
<TaskAccordionItem
lastSuccess={lastSuccess && lastSuccess[0]}
lastFailure={lastFailure}
taskData={taskData && JSON.parse(taskData)}
taskData={taskData}
/>
</AccordionItem>
);
Expand Down
4 changes: 3 additions & 1 deletion db-scheduler-ui-frontend/src/components/TaskDataRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import React from 'react';
export const TaskDataRow: React.FC<{ taskData: string | null }> = ({
taskData,
}) => {
const parsedData = JSON.parse(taskData || 'null');
console.log(taskData);
const parsedData = JSON.parse(taskData ? taskData[0] : 'null');
console.log(parsedData);
return (
<>
{parsedData !== null && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/api")
public class TaskController {
private final TaskLogic taskLogic;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.bekk.dbscheduleruibackend.model;
package com.github.bekk.dbscheduleruiapi.model;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down Expand Up @@ -73,7 +73,8 @@ public List<String> getTaskData() {
public void serializeTaskData(@Nullable List<Object> taskData) {
System.out.println("TaskData: " + taskData);
try {
this.taskData = Arrays.asList(objectMapper.writeValueAsString(taskData));
assert taskData != null;
this.taskData = Arrays.asList(objectMapper.writeValueAsString(taskData.get(0)));
} catch (JsonProcessingException e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.bekk.dbscheduleruibackend.util.mapper;
package com.github.bekk.dbscheduleruiapi.util.mapper;

import com.github.bekk.dbscheduleruibackend.model.TaskModel;
import com.github.bekk.dbscheduleruiapi.model.TaskModel;
import com.github.kagkarlsson.scheduler.CurrentlyExecuting;
import com.github.kagkarlsson.scheduler.ScheduledExecution;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ public CommandLineRunner runAllTasks(Scheduler scheduler) {
return args -> {
System.out.println("Running all tasks");
TaskService taskService = new TaskService(scheduler);
System.out.println("TaskService created");
taskService.runAllTasks();
System.out.println("tasks ran");
};
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.bekk.exampleapp.tasks;

import com.github.bekk.exampleapp.model.TaskData;
import com.github.kagkarlsson.scheduler.SchedulerClient;
import com.github.kagkarlsson.scheduler.task.Task;
import com.github.kagkarlsson.scheduler.task.helper.Tasks;
Expand All @@ -15,15 +16,15 @@ public static Task<?> runSpawner(){
final SchedulerClient client = ctx.getSchedulerClient();
final long randomUUID = UUID.randomUUID().getMostSignificantBits() & Long.MAX_VALUE;

System.out.println("Scheduling spawned executions.");
for(int i = 0; i < 5; i++){
client.schedule(runSpawned().instance("spawned " + randomUUID + " loopnr: " + i), Instant.now().plusSeconds(60));
client.schedule(runSpawned().instance("spawned " + randomUUID + " loopnr: " + i,
new TaskData(123,"{data: MASSIVEDATA}")), Instant.now().plusSeconds(60));
}
});
}

public static Task<?> runSpawned (){
return Tasks.oneTime("onetime-spawned-task", Void.class)
public static Task<TaskData> runSpawned (){
return Tasks.oneTime("onetime-spawned-task", TaskData.class)
.execute((inst, ctx) -> {
System.out.println("Executed spawned task: " + inst.getTaskName());
try {
Expand Down

0 comments on commit 5d3c608

Please sign in to comment.