Skip to content

Commit

Permalink
Jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusab committed Nov 26, 2023
1 parent d536e8a commit 844a7df
Show file tree
Hide file tree
Showing 19 changed files with 62 additions and 37 deletions.
6 changes: 2 additions & 4 deletions apps/dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@
"@midday/notification": "workspace:*",
"@midday/supabase": "workspace:*",
"@midday/ui": "workspace:*",
"@novu/headless": "^0.21.0",
"@midday/jobs": "workspace:*",
"@trigger.dev/nextjs": "^2.2.7",
"@trigger.dev/react": "^2.2.7",
"@trigger.dev/sdk": "^2.2.7",
"@trigger.dev/supabase": "^2.2.7",
"@novu/headless": "^0.21.0",
"@vercel/edge-config": "^0.4.1",
"@vercel/toolbar": "^0.1.5",
"change-case": "^5.2.0",
Expand Down
4 changes: 2 additions & 2 deletions apps/dashboard/src/actions/export-transactions-action.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use server";

import { client } from "@/trigger";
import { Events, client } from "@midday/jobs";
import { getUser } from "@midday/supabase/cached-queries";
import { action } from "./safe-action";
import { exportTransactionsSchema } from "./schema";
Expand All @@ -11,7 +11,7 @@ export const exportTransactionsAction = action(
const user = await getUser();

const event = await client.sendEvent({
name: "transactions.export",
name: Events.TRANSACTIONS_EXPORT,
payload: {
from,
to,
Expand Down
4 changes: 2 additions & 2 deletions apps/dashboard/src/app/api/trigger/route.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { client } from "@/trigger";
import { client } from "@midday/jobs";
import { createAppRoute } from "@trigger.dev/nextjs";

export const runtime = "nodejs";
export const maxDuration = 60;

import "@/jobs/transactions";
import "@midday/jobs";

export const { POST, dynamic } = createAppRoute(client);
7 changes: 0 additions & 7 deletions apps/dashboard/src/trigger.ts

This file was deleted.

Binary file modified bun.lockb
Binary file not shown.
18 changes: 18 additions & 0 deletions packages/jobs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "@midday/jobs",
"version": "1.0.0",
"private": true,
"main": "src/index.ts",
"scripts": {
"clean": "rm -rf .turbo node_modules",
"lint": "biome check .",
"format": "biome format --write .",
"check:types": "tsc --noEmit"
},
"dependencies": {
"@trigger.dev/react": "^2.2.7",
"@trigger.dev/sdk": "^2.2.7",
"@trigger.dev/supabase": "^2.2.7"
}
}

Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { Database } from "@midday/supabase/src/types";
import { TriggerClient } from "@trigger.dev/sdk";
import { Supabase, SupabaseManagement } from "@trigger.dev/supabase";

export const client = new TriggerClient({
id: "midday-CpkS",
apiKey: process.env.TRIGGER_API_KEY,
apiUrl: process.env.TRIGGER_API_URL,
});

export const supabase = new Supabase<Database>({
id: "supabase",
projectId: process.env.SUPABASE_ID!,
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions packages/jobs/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from "./transactions";
export * from "./client";
export * from "./constants";
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { client } from "@/trigger";
import { supabaseTriggers } from "../client";
import { client, supabaseTriggers } from "@/client";
import { Events, Jobs } from "../constants";
import { scheduler } from "./scheduler";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { client } from "@/trigger";
import { client, supabase } from "@/client";
import { Events, Jobs } from "@/constants";
import { processPromisesBatch } from "@/utils";
import { eventTrigger } from "@trigger.dev/sdk";
import { revalidateTag } from "next/cache";
import { z } from "zod";
import { supabase } from "../client";
import { Events, Jobs } from "../constants";
import { processPromisesBatch } from "./utils";

client.defineJob({
id: Jobs.TRANSACTIONS_ENCRICHMENT,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { client } from "@/trigger";
import { client, supabase } from "@/client";
import { Events, Jobs } from "@/constants";
import { getTransactionsQuery } from "@midday/supabase/queries";
import { eventTrigger } from "@trigger.dev/sdk";
import { z } from "zod";
import { supabase } from "../client";
import { Events, Jobs } from "../constants";

client.defineJob({
id: Jobs.TRANSACTIONS_EXPORT,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { client } from "@/trigger";
import { client, supabase } from "@/client";
import { Events, Jobs } from "@/constants";
import { transformTransactions } from "@/utils";
import { getTransactions } from "@midday/gocardless";
import { eventTrigger } from "@trigger.dev/sdk";
import { revalidateTag } from "next/cache";
import { z } from "zod";
import { supabase } from "../client";
import { Events, Jobs } from "../constants";
import { transformTransactions } from "./utils";

client.defineJob({
id: Jobs.TRANSACTIONS_INITIAL_SYNC,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { client } from "@/trigger";
import { client, supabase } from "@/client";
import { Events, Jobs } from "@/constants";
import TransactionsEmail from "@midday/email/emails/transactions";
import { getI18n } from "@midday/email/locales";
import { TriggerEvents, triggerBulk } from "@midday/notification";
import { renderAsync } from "@react-email/components";
import { eventTrigger } from "@trigger.dev/sdk";
import { revalidateTag } from "next/cache";
import { z } from "zod";
import { supabase } from "../client";
import { Events, Jobs } from "../constants";

client.defineJob({
id: Jobs.TRANSACTIONS_NOTIFICATION,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { client } from "@/trigger";
import { Jobs } from "../constants";
import { client } from "@/client";
import { Jobs } from "@/constants";

export const scheduler = client.defineDynamicSchedule({
id: Jobs.TRANSACTION_SCHEDULER,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { client } from "@/trigger";
import { client, supabase } from "@/client";
import { Events, Jobs } from "@/constants";
import { transformTransactions } from "@/utils";
import { getTransactions } from "@midday/gocardless";
import { revalidateTag } from "next/cache";
import { supabase } from "../client";
import { Events, Jobs } from "../constants";
import { scheduler } from "./scheduler";
import { transformTransactions } from "./utils";

client.defineJob({
id: Jobs.TRANSACTIONS_SYNC,
Expand Down
File renamed without changes.
11 changes: 11 additions & 0 deletions packages/jobs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
},
},
"include": ["src", "*.ts"]
}

0 comments on commit 844a7df

Please sign in to comment.