fix(hardcover): use injected restclient with expected timeouts (#2320)

This commit is contained in:
James Ward
2026-08-12 04:05:29 -04:00
committed by GitHub
parent 41fa0c107a
commit 9d15192c18
4 changed files with 20 additions and 19 deletions
@@ -43,12 +43,14 @@ public class HardcoverSyncService {
private final ThreadLocal<String> currentApiToken = new ThreadLocal<>();
@Autowired
public HardcoverSyncService(HardcoverSyncSettingsService hardcoverSyncSettingsService, BookRepository bookRepository) {
public HardcoverSyncService(
HardcoverSyncSettingsService hardcoverSyncSettingsService,
BookRepository bookRepository,
RestClient restClient
) {
this.hardcoverSyncSettingsService = hardcoverSyncSettingsService;
this.bookRepository = bookRepository;
this.restClient = RestClient.builder()
.baseUrl(HARDCOVER_API_URL)
.build();
this.restClient = restClient;
}
/**
@@ -795,7 +797,7 @@ public class HardcoverSyncService {
private Map<String, Object> executeGraphQL(GraphQLRequest request) {
try {
return restClient.post()
.uri("")
.uri(HARDCOVER_API_URL)
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.header(HttpHeaders.AUTHORIZATION, "Bearer " + getApiToken())
.body(request)
@@ -16,7 +16,7 @@ import java.util.concurrent.atomic.AtomicLong;
@Slf4j
@Service
public class HardcoverBookSearchService {
private static final String GRAPHQL_URI = "https://api.hardcover.app/v1/graphql";
public static final int DEFAULT_PER_PAGE = 10;
private static final long INITIAL_DELAY_MS = 1000;
private static final long MAX_DELAY_MS = 15000;
@@ -27,11 +27,9 @@ public class HardcoverBookSearchService {
private final AtomicLong lastRequestTime = new AtomicLong(0);
private final AtomicLong successCount = new AtomicLong(0);
public HardcoverBookSearchService(AppSettingService appSettingService) {
public HardcoverBookSearchService(AppSettingService appSettingService, RestClient restClient) {
this.appSettingService = appSettingService;
this.restClient = RestClient.builder()
.baseUrl("https://api.hardcover.app/v1/graphql")
.build();
this.restClient = restClient;
}
public List<GraphQLResponse.BookWithEditions> searchBookByIsbn(List<String> isbn) {
@@ -169,7 +167,7 @@ public class HardcoverBookSearchService {
try {
T response = restClient.post()
.uri("")
.uri(GRAPHQL_URI)
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.header(HttpHeaders.AUTHORIZATION, "Bearer " + apiToken)
.body(body)