Skip to content

Commit

Permalink
Job
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusab committed Nov 13, 2023
1 parent 760ecf1 commit 00ed0fb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
4 changes: 4 additions & 0 deletions apps/dashboard/src/components/charts/realtime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import { invalidateCacheAction } from "@/actions/invalidate-cache-action";
import { createClient } from "@midday/supabase/client";
import { useRouter } from "next/navigation";
import { useEffect } from "react";

export function Realtime({ teamId }) {
const supabase = createClient();
const router = useRouter();

useEffect(() => {
const channel = supabase
Expand All @@ -24,6 +26,8 @@ export function Realtime({ teamId }) {
`spending-${teamId}`,
`metrics-${teamId}`,
]);

router.refresh();
}
)
.subscribe();
Expand Down
14 changes: 10 additions & 4 deletions apps/dashboard/src/jobs/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ client.defineJob({
await dynamicSchedule.register(payload.record.id, {
type: "interval",
options: {
// seconds: 3600,
seconds: 10 * 60, // 10 minutes
},
});
Expand Down Expand Up @@ -114,7 +113,7 @@ client.defineJob({
await io.logger.info("No transactions found");
}

const { count, error } = await io.supabase.client
const { data: transactionsData, error } = await io.supabase.client
.from("transactions")
.upsert(
transformTransactions(transactions?.booked, {
Expand All @@ -125,13 +124,20 @@ client.defineJob({
onConflict: "internal_id",
ignoreDuplicates: true,
}
);
)
.select("*");

if (error) {
await io.logger.error(JSON.stringify(error, null, 2));
}

await io.logger.info(`Total Transactions Created: ${count}`);
await io.logger.info(
`Total Transactions Created: ${transactionsData?.length}`
);

await io.logger.info(`Revalidating cache: transactions_${data?.team_id}`);

await io.logger.error(JSON.stringify(transactionsData, null, 2));

revalidateTag(`transactions_${data?.team_id}`);
revalidateTag(`spending_${data?.team_id}`);
Expand Down

0 comments on commit 00ed0fb

Please sign in to comment.