Added new end point, edited getEmails to be Async all and return 202 status code

This commit is contained in:
heyethereum
2024-08-04 19:37:16 +08:00
parent 0fde70a4b6
commit 76036a2d91
17 changed files with 593 additions and 27 deletions

View File

@@ -0,0 +1,34 @@
package com.safeqr.app.utils;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.context.annotation.Bean;
import java.util.concurrent.Executor;
@Configuration
@EnableAsync
public class AsyncConfig {
@Bean(name = "taskExecutor")
public Executor taskExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
// Sets the number of core threads. These threads are always kept alive.
executor.setCorePoolSize(2);
// Sets the maximum number of threads that can be created by the pool.
executor.setMaxPoolSize(2);
// Sets the size of the queue to hold tasks before they are executed.
executor.setQueueCapacity(500);
// Sets the prefix for the names of the threads created by this pool.
executor.setThreadNamePrefix("GmailProcessing-");
// Initializes the executor to apply the configuration and make it ready to use.
executor.initialize();
return executor;
}
}

View File

@@ -0,0 +1,42 @@
package com.safeqr.app.utils;
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.time.temporal.ChronoField;
import java.util.Locale;
public class DateParsingUtils {
private DateParsingUtils() {
// private constructor to hide the implicit public one
}
private static final DateTimeFormatter INPUT_FORMATTER = new DateTimeFormatterBuilder()
.appendPattern("EEE, ")
.appendPattern("[ ]") // This makes a single space optional
.appendPattern("[ ]") // This allows for a second optional space
.appendValue(ChronoField.DAY_OF_MONTH, 1, 2, java.time.format.SignStyle.NOT_NEGATIVE)
.appendPattern(" MMM yyyy HH:mm:ss Z")
.toFormatter(Locale.ENGLISH);
private static final DateTimeFormatter OUTPUT_FORMATTER =
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS Z");
public static String parseAndFormatDate(String inputDate) {
try {
OffsetDateTime dateTime = OffsetDateTime.parse(inputDate, INPUT_FORMATTER);
return dateTime.format(OUTPUT_FORMATTER);
} catch (Exception e) {
throw new RuntimeException("Error parsing date: " + inputDate, e);
}
}
public static OffsetDateTime parseDate(String inputDate) {
try {
return OffsetDateTime.parse(inputDate, INPUT_FORMATTER);
} catch (Exception e) {
throw new RuntimeException("Error parsing date: " + inputDate, e);
}
}
}