Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@ build/

### upload files ###
uploads/

# Local run script
run-backend.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.thughari.jobtrackerpro.config;

import com.thughari.jobtrackerpro.repo.UserRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class StartupInitializer implements CommandLineRunner {

private final UserRepository userRepository;

public StartupInitializer(UserRepository userRepository) {
this.userRepository = userRepository;
}

@Override
public void run(String... args) throws Exception {
log.info("System Startup: Resetting all active Gmail sync locks.");
userRepository.resetAllSyncLocks();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public ResponseEntity<String> connectGmail(@RequestBody Map<String, String> body

try {
gmailAutomationService.connectAndSetupPush(authCode, email);
gmailAutomationService.initiateManualSync(email);
return ResponseEntity.ok("Gmail Automation enabled successfully.");
} catch (Exception e) {
log.error("Failed to setup Gmail for user {}: {}", email, e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ public class DashboardResponse {
private List<ChartData> statusChart;
private List<ChartData> monthlyChart;
private List<ChartData> interviewChart;
private boolean gmailSyncInProgress;
private String gmailSyncStatus;
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public class User {
@Column(name = "gmail_sync_started_at")
private LocalDateTime gmailSyncStartedAt;

@Column(name = "gmail_sync_status")
private String gmailSyncStatus;

@Column(name = "gmail_connected")
private Boolean gmailConnected = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ public interface UserRepository extends JpaRepository<User, UUID> {
@Query("UPDATE User u SET u.gmailSyncInProgress = false WHERE u.email = :email")
void releaseSyncLock(@Param("email") String email);

@Modifying
@Transactional
@Query("UPDATE User u SET u.gmailSyncInProgress = false, u.gmailSyncStatus = null")
void resetAllSyncLocks();

@Modifying
@Transactional
@Query("UPDATE User u SET u.gmailSyncStatus = :status WHERE u.email = :email")
void updateSyncStatus(@Param("email") String email, @Param("status") String status);

List<User> findByGmailConnectedTrue();

@Modifying
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestClient;

import java.time.LocalDateTime;
Expand Down Expand Up @@ -63,6 +64,13 @@ public JobDTO extractJobFromEmail(String from, String subject, String body) {

return parseGeminiResponse(response);

} catch (HttpClientErrorException e) {
if (e.getStatusCode().value() == 429) {
log.error("Gemini API quota/rate limit exceeded: {}", e.getResponseBodyAsString());
throw new RuntimeException("GEMINI_QUOTA_EXCEEDED", e);
}
log.error("AI Extraction failed or timed out: {}", e.getMessage());
return null;
} catch (Exception e) {
log.error("AI Extraction failed or timed out", e);
return null;
Expand Down Expand Up @@ -91,6 +99,13 @@ public List<JobDTO> extractJobsFromBatch(List<EmailBatchItem> items) {

return parseBulkGeminiResponse(response);

} catch (HttpClientErrorException e) {
if (e.getStatusCode().value() == 429) {
log.error("Gemini API quota/rate limit exceeded: {}", e.getResponseBodyAsString());
throw new RuntimeException("GEMINI_QUOTA_EXCEEDED", e);
}
log.error("Bulk AI Extraction failed: {}", e.getMessage());
return List.of();
} catch (Exception e) {
log.error("Bulk AI Extraction failed", e);
return List.of();
Expand Down
Loading