-
Notifications
You must be signed in to change notification settings - Fork 596
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
48 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,38 @@ | ||
import { schedules, schemaTask } from "@trigger.dev/sdk/v3"; | ||
import { generateCron } from "jobs/utils/generate-cron"; | ||
import { z } from "zod"; | ||
import { scheduleBankSync } from "../scheduler/bank-sync"; | ||
import { bankSyncScheduler } from "../scheduler/bank-sync"; | ||
import { syncConnection } from "../sync/connection"; | ||
|
||
// This task sets up the bank sync for a new team on a daily schedule and | ||
// runs the initial sync for transactions and balance | ||
export const initialBankSetup = schemaTask({ | ||
id: "initial-bank-setup", | ||
schema: z.object({ | ||
teamId: z.string().uuid(), | ||
connectionId: z.string().uuid(), | ||
}), | ||
maxDuration: 600, | ||
queue: { | ||
concurrencyLimit: 20, | ||
}, | ||
run: async (payload) => { | ||
const { teamId } = payload; | ||
const { teamId, connectionId } = payload; | ||
|
||
// Schedule the bank sync task to run daily at a random time to distribute load | ||
// Use a deduplication key to prevent duplicate schedules for the same team | ||
// Add teamId as externalId to use it in the scheduleBankSync task | ||
// Add teamId as externalId to use it in the bankSyncScheduler task | ||
await schedules.create({ | ||
task: scheduleBankSync.id, | ||
task: bankSyncScheduler.id, | ||
cron: generateCron(teamId), | ||
timezone: "UTC", | ||
externalId: teamId, | ||
deduplicationKey: `${teamId}-${scheduleBankSync.id}`, | ||
deduplicationKey: `${teamId}-${bankSyncScheduler.id}`, | ||
}); | ||
|
||
// Run manual sync | ||
// --> Transactions | ||
// --> Balance | ||
// Run initial sync for transactions and balance for the connection | ||
await syncConnection.trigger({ | ||
connectionId, | ||
}); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { schemaTask } from "@trigger.dev/sdk/v3"; | ||
import { z } from "zod"; | ||
|
||
// This task trigger a sync for a specific provider | ||
export const syncProvider = schemaTask({ | ||
id: "sync-provider", | ||
schema: z.object({ | ||
provider: z.enum(["gocardless", "plaid", "teller"]), | ||
}), | ||
run: async ({ provider }) => { | ||
// TODO: Implement | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters