Skip to content

Commit

Permalink
Save statistics control status
Browse files Browse the repository at this point in the history
  • Loading branch information
campos20 committed Sep 23, 2024
1 parent 43d9870 commit 921ce2f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.worldcubeassociation.statistics.enums;

public enum StatisticsControlStatus {
STARTED,
COMPLETED,
FAILED
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class StatisticsControl extends BaseEntity {

private String message;

private String status;

@Column(name = "created_at")
private LocalDateTime createdAt;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.worldcubeassociation.statistics.dto.StatisticsRequestDTO;
import org.worldcubeassociation.statistics.dto.StatisticsResponseDTO;
import org.worldcubeassociation.statistics.enums.DisplayModeEnum;
import org.worldcubeassociation.statistics.enums.StatisticsControlStatus;
import org.worldcubeassociation.statistics.exception.NotFoundException;
import org.worldcubeassociation.statistics.model.Statistics;
import org.worldcubeassociation.statistics.model.StatisticsControl;
Expand Down Expand Up @@ -180,6 +181,7 @@ private void resourcesToStatistics(List<Resource> resources) throws IOException
var statisticsControl = new StatisticsControl();
statisticsControl.setPath(resource.getFilename());
statisticsControl.setCreatedAt(LocalDateTime.now());
statisticsControl.setStatus(StatisticsControlStatus.STARTED.name());
statisticsControlRepository.save(statisticsControl);

try {
Expand All @@ -190,10 +192,12 @@ private void resourcesToStatistics(List<Resource> resources) throws IOException
sqlToStatistics(request);

statisticsControl.setCompletedAt(LocalDateTime.now());
statisticsControl.setStatus(StatisticsControlStatus.COMPLETED.name());
statisticsControlRepository.save(statisticsControl);
} catch (Exception e) {
log.error("Error while processing {}", resource.getFilename(), e);
statisticsControl.setMessage(StringUtils.abbreviate(e.getMessage(), 200));
statisticsControl.setStatus(StatisticsControlStatus.FAILED.name());
statisticsControlRepository.save(statisticsControl);
}
}
Expand Down
1 change: 1 addition & 0 deletions server/src/main/resources/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ create table if not exists statistics (

create table if not exists statistics_control (
path varchar(100),
status varchar(20) not null,
message varchar(200),
created_at datetime not null,
completed_at datetime,
Expand Down

0 comments on commit 921ce2f

Please sign in to comment.