Skip to content

Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.

feat: implement syncSchedulerState function to manage scheduler based on active automations refactor: rename prompt function for clarity in resume review prompt generation refactor: replace hardcoded MAX_AUTOMATIONS_PER_USER with APP_CONSTANTS in automation actions refactor: optimize connection status check in AiResumeReviewSection component

Khuram Niaz0e04a776e19d
diff --git a/evals/resume-review/prompt.ts b/evals/resume-review/prompt.ts
index ced7f04..1e8d27b 100644
--- a/evals/resume-review/prompt.ts
+++ b/evals/resume-review/prompt.ts
@@ -1,7 +1,7 @@
import { RESUME_REVIEW_SYSTEM_PROMPT } from '../../src/lib/ai/prompts/resume-review/system';
import { buildResumeReviewPrompt } from '../../src/lib/ai/prompts/resume-review/user';
-export default function({ vars }: { vars: Record<string, string> }) {
+export default function prompt({ vars }: { vars: Record<string, string> }) {
return [
{ role: 'system', content: RESUME_REVIEW_SYSTEM_PROMPT },
{ role: 'user', content: buildResumeReviewPrompt(vars.resumeText) },
diff --git a/src/actions/automation.actions.ts b/src/actions/automation.actions.ts
index 43b0975..fe71efa 100644
--- a/src/actions/automation.actions.ts
+++ b/src/actions/automation.actions.ts
@@ -16,8 +16,8 @@ import type {
DiscoveryStatus,
} from "@/models/automation.model";
import { APP_CONSTANTS } from "@/lib/constants";
+import { syncSchedulerState } from "@/lib/scheduler";
-const MAX_AUTOMATIONS_PER_USER = 10;
function formatError(error: unknown, fallback: string): { success: false; message: string } {
console.error(error, fallback);
@@ -122,8 +122,8 @@ export async function createAutomation(
const validated = CreateAutomationSchema.parse(input);
const count = await db.automation.count({ where: { userId: user.id } });
- if (count >= MAX_AUTOMATIONS_PER_USER) {
- return { success: false, message: `Maximum of ${MAX_AUTOMATIONS_PER_USER} automations allowed per user` };
+ if (count >= APP_CONSTANTS.MAX_AUTOMATIONS_PER_USER) {
+ return { success: false, message: `Maximum of ${APP_CONSTANTS.MAX_AUTOMATIONS_PER_USER} automations allowed per user` };
}
const resume = await db.resume.findFirst({
@@ -159,6 +159,8 @@ export async function createAutomation(
},
});
+ await syncSchedulerState();
+
return {
success: true,
data: automation as unknown as AutomationWithResume,
@@ -249,6 +251,8 @@ export async function deleteAutomation(id: string): Promise<{
await db.automation.delete({ where: { id } });
+ await syncSchedulerState();
+
return { success: true };
} catch (error) {
return formatError(error, "Failed to delete automation");
@@ -287,6 +291,8 @@ export async function pauseAutomation(id: string): Promise<{
},
});
+ await syncSchedulerState();
+
return {
success: true,
data: updated as unknown as AutomationWithResume,
@@ -330,6 +336,8 @@ export async function resumeAutomation(id: string): Promise<{
},
});
+ await syncSchedulerState();
+
return {
success: true,
data: updated as unknown as AutomationWithResume,
diff --git a/src/components/profile/AiResumeReviewSection.tsx b/src/components/profile/AiResumeReviewSection.tsx
index 8d17d1a..744129a 100644
--- a/src/components/profile/AiResumeReviewSection.tsx
+++ b/src/components/profile/AiResumeReviewSection.tsx
@@ -12,7 +12,7 @@ import {
SheetTrigger,
} from "../ui/sheet";
import Loading from "../Loading";
-import { useState, useEffect } from "react";
+import { useState, useEffect, useCallback } from "react";
import { toast } from "../ui/use-toast";
import { Resume } from "@/models/profile.model";
import { AiModel, defaultModel } from "@/models/ai.model";
@@ -40,6 +40,18 @@ const AiResumeReviewSection = ({ resume }: AiSectionProps) => {
const [selectedModel, setSelectedModel] = useState<AiModel>(defaultModel);
const [isLoadingSettings, setIsLoadingSettings] = useState(false);
+ const checkConnectionStatus = useCallback(async (provider: string) => {
+ setOllamaConnected(null);
+ setConnectionError("");
+ const result = await checkOllamaConnection(provider);
+ if (result.isConnected) {
+ setOllamaConnected(true);
+ } else {
+ setOllamaConnected(false);
+ setConnectionError(result.error || "Ollama is not reachable.");
+ }
+ }, []);
+
useEffect(() => {
if (!aISectionOpen) return;
const fetchSettings = async () => {
@@ -64,7 +76,7 @@ const AiResumeReviewSection = ({ resume }: AiSectionProps) => {
}
};
fetchSettings();
- }, [aISectionOpen]);
+ }, [aISectionOpen, checkConnectionStatus]);
// Standard single-agent mode
const { object, submit, isLoading, stop } = useObject({
@@ -100,18 +112,6 @@ const AiResumeReviewSection = ({ resume }: AiSectionProps) => {
}
};
- const checkConnectionStatus = async (provider = selectedModel.provider) => {
- setOllamaConnected(null);
- setConnectionError("");
- const result = await checkOllamaConnection(provider);
- if (result.isConnected) {
- setOllamaConnected(true);
- } else {
- setOllamaConnected(false);
- setConnectionError(result.error || "Ollama is not reachable.");
- }
- };
-
// Check if we have any content to show
const hasContent =
object && (object.scores?.overall !== undefined || object.summary);
diff --git a/src/instrumentation.ts b/src/instrumentation.ts
index dc90a71..f7e3c12 100644
--- a/src/instrumentation.ts
+++ b/src/instrumentation.ts
@@ -1,6 +1,6 @@
export async function register() {
if (process.env.NEXT_RUNTIME === "nodejs") {
- const { startScheduler } = await import("@/lib/scheduler");
- startScheduler();
+ const { syncSchedulerState } = await import("@/lib/scheduler");
+ await syncSchedulerState();
}
}
diff --git a/src/lib/constants.ts b/src/lib/constants.ts
index 25e8fe5..9f0ffa3 100644
--- a/src/lib/constants.ts
+++ b/src/lib/constants.ts
@@ -12,6 +12,7 @@ import {
export const APP_CONSTANTS = {
RECORDS_PER_PAGE: 25,
+ MAX_AUTOMATIONS_PER_USER: 10,
ACTIVITY_MAX_DURATION_MINUTES: 8 * 60, // 8 Hours
ACTIVITY_MAX_DURATION_MS: 8 * 60 * 60 * 1000, // 8 hours in milliseconds
RECENT_NUM_JOBS_ACTIVITIES: 7,
diff --git a/src/lib/scheduler/index.ts b/src/lib/scheduler/index.ts
index 1a1b950..c2703b9 100644
--- a/src/lib/scheduler/index.ts
+++ b/src/lib/scheduler/index.ts
@@ -108,3 +108,13 @@ export function stopScheduler() {
export function isSchedulerRunning(): boolean {
return scheduledTask !== null;
}
+
+// Starts or stops the scheduler based on whether active automations exist
+export async function syncSchedulerState() {
+ const activeCount = await db.automation.count({ where: { status: "active" } });
+ if (activeCount > 0) {
+ startScheduler();
+ } else {
+ stopScheduler();
+ }
+}