Skip to content

Commit 3a5dec9

Browse files
committed
My way of trying to re-enqueue tasks manually is out of touch with my design. I am not organized.
1 parent 59499e9 commit 3a5dec9

3 files changed

Lines changed: 18 additions & 10 deletions

File tree

‎springqpro-backend/src/main/java/com/springqprobackend/springqpro/controller/graphql/TaskGraphQLController.java‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ public boolean retryTask(@Argument String id, Authentication auth) {
135135
// ownership check:
136136
taskService.getTaskForUser(id, owner).orElseThrow(() -> new RuntimeException("Task not found or not owned by user."));
137137
return processingService.manuallyRequeue(id);
138-
//return processingService.manuallyRequeue(id);
139138
}
140139

141140
/* 2025-12-04-NOTE: Adding a new method in the GraphQL Controller that exposes enums (useful for frontends

‎springqpro-backend/src/main/java/com/springqprobackend/springqpro/service/ProcessingService.java‎

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.springqprobackend.springqpro.service;
22

33
import com.springqprobackend.springqpro.domain.entity.TaskEntity;
4+
import com.springqprobackend.springqpro.domain.event.TaskCreatedEvent;
45
import com.springqprobackend.springqpro.enums.TaskStatus;
56
import com.springqprobackend.springqpro.handlers.TaskHandler;
67
import com.springqprobackend.springqpro.mapper.TaskMapper;
@@ -13,8 +14,10 @@
1314
import jakarta.persistence.PersistenceContext;
1415
import org.slf4j.Logger;
1516
import org.slf4j.LoggerFactory;
17+
import org.springframework.beans.factory.annotation.Autowired;
1618
import org.springframework.beans.factory.annotation.Qualifier;
1719
import org.springframework.context.annotation.Lazy;
20+
import org.springframework.context.ApplicationEventPublisher;
1821
import org.springframework.stereotype.Service;
1922
import org.springframework.transaction.annotation.Transactional;
2023
import io.micrometer.core.instrument.Counter;
@@ -127,6 +130,9 @@ public class ProcessingService {
127130
private final RedisDistributedLock redisLock; // 2025-11-23-DEBUG: REDIS INTEGRATION PHASE!
128131
private final TaskRedisRepository cache; // 2025-11-23-DEBUG: Refactoring for TaskRedisRepository.java
129132

133+
@Autowired
134+
private ApplicationEventPublisher publisher;
135+
130136
// 2025-11-26-NOTE:+DEBUG: METRICS PHASE FIELD ADDITIONS:
131137
private final Counter tasksSubmittedCounter;
132138
private final Counter tasksClaimedCounter;
@@ -264,25 +270,28 @@ public void claimAndProcess(String taskId) {
264270
@Transactional
265271
public boolean manuallyRequeue(String taskId) {
266272
Optional<TaskEntity> opt = taskRepository.findById(taskId);
267-
if(opt.isEmpty()) return false;
268-
273+
if(opt.isEmpty()) {
274+
logger.warn("[ManualRequeue] Task {} not found.", taskId);
275+
return false;
276+
}
269277
TaskEntity task = opt.get();
270278
// Only FAILED tasks may be manually requeued
271279
if (task.getStatus() != TaskStatus.FAILED) {
272280
logger.warn("[ManualRequeue] Task {} is not FAILED, ignoring.", taskId);
273281
return false;
274282
}
275-
// Reset status to QUEUED for the sake of auto-retry:
283+
// Reset status to QUEUED (and attempts to 0) for the sake of auto-retry:
276284
int updated = taskRepository.transitionStatus(taskId, TaskStatus.FAILED, TaskStatus.QUEUED, 0);
277285
if(updated == 0) {
278286
logger.warn("[ManualRequeue] DB Transition FAILED->QUEUED did not update any rows.");
279287
return false;
280288
}
281-
// Update the cache:
282-
cache.put(task);
283-
// Push into in-memory queue immediately:
284-
queueService.enqueueById(taskId);
285-
logger.info("[ManualRequeue] Task {} successfully re-enqueued manually.", taskId);
289+
// Re-read the fresh entity and update the cache:
290+
TaskEntity refreshed = taskRepository.findById(taskId).orElseThrow();
291+
cache.put(refreshed);
292+
// Publish event - the listener will call enqueueById after the AFTER COMMIT (this is deliberate, can't directly call enqueueById, it's a bad idea):
293+
publisher.publishEvent(new TaskCreatedEvent(this, taskId));
294+
logger.info("[ManualRequeue] Task {} successfully re-enqueued manually (AFTER_COMMIT will enqueue worker).", taskId);
286295
return true;
287296
}
288297

‎springqpro-backend/src/main/resources/graphql/schema.graphqls‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,5 @@ type Mutation {
9999
2025-12-05-NOTE: Adding this one for the frontend...
100100
Retrying a Task by ID:
101101
"""
102-
retryTask(id: ID!): Task!
102+
retryTask(id: ID!): Boolean!
103103
}

0 commit comments

Comments
 (0)