Skip to content

Commit

Permalink
Added new scheduled method to regenerate the questions each 24 hours
Browse files Browse the repository at this point in the history
  • Loading branch information
uo287545 committed Apr 26, 2024
1 parent a49cc53 commit 33fdce6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/main/java/com/uniovi/services/QuestionGeneratorService.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ public class QuestionGeneratorService {

private Logger log = LoggerFactory.getLogger(InsertSampleDataService.class);

private boolean started;

public QuestionGeneratorService(QuestionService questionService) {
this.questionService = questionService;
parseQuestionTypes();
this.started = true;
}

private void parseQuestionTypes() {
Expand All @@ -63,13 +66,22 @@ private void parseQuestionTypes() {
}
}

@Scheduled(fixedRate = 86400000, initialDelay = 86400000)
public void generateAllQuestions(){
}

@Scheduled(fixedRate = 150000)
@Transactional
public void generateQuestions() throws IOException {
if (types.isEmpty()) {
return;
}

if (started){
started = false;
questionService.deleteAllQuestions();
}

if (Arrays.stream(environment.getActiveProfiles()).anyMatch(env -> (env.equalsIgnoreCase("test")))) {
log.info("Test profile active, skipping sample data insertion");
return;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/uniovi/services/QuestionService.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,9 @@ public interface QuestionService {
* @param id The id of the question to delete
*/
void deleteQuestion(Long id);

/**
* Delete all the questions
*/
void deleteAllQuestions();
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,9 @@ public void deleteQuestion(Long id) {
questionRepository.delete(question);
}
}

@Override
public void deleteAllQuestions() {
questionRepository.deleteAll();
}
}

0 comments on commit 33fdce6

Please sign in to comment.