Skip to content

Commit

Permalink
Fixed trigger related issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Luisotee committed Jan 22, 2025
1 parent ff86fea commit a01eda5
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 27 deletions.
56 changes: 36 additions & 20 deletions apps/messaging/src/routes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { config } from "@eda/config";
import { logger } from "@eda/logger";
import { createClient } from "@supabase/supabase-js";
import { tasks } from "@trigger.dev/sdk/v3";
import { configure, tasks } from "@trigger.dev/sdk/v3";
import { type Message, messageSchema, queryParamsSchema } from "./types";

// Replace Supabase client initialization
Expand All @@ -10,6 +10,11 @@ const supabase = createClient(
config.api_keys.supabase.service_key,
);

configure({
secretKey: config.api_keys.trigger,
baseURL: config.services.trigger.api_url,
});

// Replace AI API URL constant
const AI_API_URL = `http://localhost:${config.ports.ai_api}`;

Expand Down Expand Up @@ -187,15 +192,19 @@ export async function handleSendMessage(req: Request) {

logger.info("Triggering monitor-api-call task");

// Monitor API call using Trigger.dev
await tasks.trigger("monitor-api-call", {
endpoint: "/api/classifier/classify",
method: "POST",
statusCode: response.status,
duration,
timestamp: new Date().toISOString(),
sessionId: payload.sessionId,
});
try {
// Monitor API call using Trigger.dev
await tasks.trigger("monitor-api-call", {
endpoint: "/api/classifier/classify",
method: "POST",
statusCode: response.status,
duration,
timestamp: new Date().toISOString(),
sessionId: payload.sessionId,
});
} catch (triggerError) {
logger.error("Error triggering monitoring task:", triggerError);
}

if (!response.ok) {
throw new Error(data.message || "Failed to process message");
Expand All @@ -216,16 +225,23 @@ export async function handleSendMessage(req: Request) {
} catch (error) {
const duration = performance.now() - startTime;

// Monitor failed API calls
await tasks.trigger("monitor-api-call", {
endpoint: "/api/classifier/classify",
method: "POST",
statusCode: 500,
duration,
timestamp: new Date().toISOString(),
sessionId: payload.sessionId, // Now safe to use since payload is initialized
error: error instanceof Error ? error.message : "Unknown error",
});
try {
// Monitor failed API calls
await tasks.trigger("monitor-api-call", {
endpoint: "/api/classifier/classify",
method: "POST",
statusCode: 500,
duration,
timestamp: new Date().toISOString(),
sessionId: payload.sessionId,
error: error instanceof Error ? error.message : "Unknown error",
});
} catch (triggerError) {
logger.error(
"Error triggering monitoring task for failed call:",
triggerError,
);
}

const message =
error instanceof Error ? error.message : "Failed to process message";
Expand Down
2 changes: 1 addition & 1 deletion apps/whatsapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"typescript": "^5.0.0"
},
"dependencies": {
"@trigger.dev/sdk": "3.2.1",
"@trigger.dev/sdk": "3.3.11",
"@types/common-tags": "^1.8.4",
"@whiskeysockets/baileys": "^6.7.9",
"common-tags": "^1.8.2",
Expand Down
3 changes: 1 addition & 2 deletions apps/whatsapp/src/message/message.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { logger } from "@trigger.dev/sdk/v3";
import { logger } from "@eda/logger";
import { type WAMessage, downloadMediaMessage } from "@whiskeysockets/baileys";
import { sock } from "../client";
import { BOT_PREFIX } from "../constants";
import { getPhoneNumber, react } from "../utils";

const IMAGE_ERROR_MSG =
Expand Down
Binary file modified bun.lockb
Binary file not shown.
6 changes: 3 additions & 3 deletions packages/jobs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"clean": "rm -rf .turbo node_modules",
"lint": "biome lint ./trigger ./lib",
"dev": "bunx trigger.dev dev",
"dev": "bunx trigger.dev dev --skip-update-check",
"format": "biome format --write .",
"typecheck": "tsc-files --noEmit",
"test": "vitest"
Expand All @@ -14,10 +14,10 @@
"@eda/supabase": "workspace:*",
"@eda/types": "workspace:*",
"@getzep/zep-cloud": "^2.1.1",
"@trigger.dev/sdk": "3.2.1"
"@trigger.dev/sdk": "3.3.11"
},
"devDependencies": {
"@trigger.dev/build": "3.2.1",
"@trigger.dev/build": "3.3.11",
"vitest": "^2.1.5"
}
}
2 changes: 1 addition & 1 deletion packages/simulator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@cerebras/cerebras_cloud_sdk": "^1.8.0",
"@eda/logger": "workspace:*",
"@eda/types": "workspace:*",
"@trigger.dev/sdk": "3.2.1",
"@trigger.dev/sdk": "3.3.11",
"dotenv": "^16.4.5",
"groq-sdk": "^0.7.0"
},
Expand Down

0 comments on commit a01eda5

Please sign in to comment.