Skip to content

Commit

Permalink
Add extra logging in TaskStateRepository and SchedulerAwareTaskExecut…
Browse files Browse the repository at this point in the history
…ionEnvironment
  • Loading branch information
kamil-sita committed Jun 8, 2024
1 parent fd3e436 commit 155d140
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package place.sita.magicscheduler.scheduler;

import org.jooq.DSLContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;
import place.sita.labelle.core.persistence.ex.UnexpectedDatabaseReplyException;
import place.sita.labelle.jooq.enums.TaskExecutionResult;
Expand All @@ -16,6 +18,8 @@
@Repository
public class TaskStateRepository {

private static final Logger log = LoggerFactory.getLogger(TaskStateRepository.class);

private final DSLContext dslContext;

public TaskStateRepository(DSLContext dslContext) {
Expand All @@ -33,6 +37,18 @@ public void assignState(UUID id, TaskStatus status) {
.where(TASK.ID.eq(id))
.execute();
if (u != 1) {
boolean exists = dslContext
.fetchExists(TASK, TASK.ID.eq(id));
if (exists) {
TaskStatus currentStatus = dslContext
.select(TASK.STATUS)
.from(TASK)
.where(TASK.ID.eq(id))
.fetchOne(TASK.STATUS);
log.error("Failed to update task status for task {} with status {} to status {}", id, currentStatus, status);
} else {
log.error("Failed to update task status for task {} to status {} - it does not exist", id, status);
}
throw new UnexpectedDatabaseReplyException();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package place.sita.magicscheduler.scheduler.environment;

import org.jooq.DSLContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
Expand All @@ -13,6 +14,8 @@
import java.time.Instant;
import java.util.UUID;

import static place.sita.labelle.jooq.Tables.TASK;

@Component
public class SchedulerAwareTaskExecutionEnvironment {
private static final Logger log = LoggerFactory.getLogger(SchedulerAwareTaskExecutionEnvironment.class);
Expand All @@ -24,23 +27,31 @@ public class SchedulerAwareTaskExecutionEnvironment {
private final PlatformTransactionManager platformTransactionManager;
private final ExecutionResultsSubmitter executionResultsSubmitter;
private final TaskExecutionEnvironment taskExecutionEnvironment;
private final DSLContext dslContext;

public SchedulerAwareTaskExecutionEnvironment(
InternalTaskSubmitter internalTaskSubmitter,
TaskStateRepository taskStateRepository,
SoftToHardFailPolicy softToHardFailPolicy,
PlatformTransactionManager platformTransactionManager,
ExecutionResultsSubmitter executionResultsSubmitter,
TaskExecutionEnvironment taskExecutionEnvironment) {
TaskExecutionEnvironment taskExecutionEnvironment,
DSLContext dslContext) {
this.internalTaskSubmitter = internalTaskSubmitter;
this.taskStateRepository = taskStateRepository;
this.softToHardFailPolicy = softToHardFailPolicy;
this.platformTransactionManager = platformTransactionManager;
this.executionResultsSubmitter = executionResultsSubmitter;
this.taskExecutionEnvironment = taskExecutionEnvironment;
this.dslContext = dslContext;
}

public <ParameterT, AcceptedContextT, ResultT> ApiTaskExecutionResult executeTask(UUID taskId, TaskType<ParameterT, AcceptedContextT, ResultT> type, ParameterT parameter, int failsSoFar) {
boolean exists = dslContext
.fetchExists(TASK, TASK.ID.eq(taskId));
if (!exists) {
log.error("Task {} does not exist in the database", taskId);
}
taskStateRepository.assignState(taskId, TaskStatus.IN_PROGRESS);

Instant start = Instant.now();
Expand Down

0 comments on commit 155d140

Please sign in to comment.