Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/database-migrations-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ jobs:
with:
bun-version: latest

- name: Install dependencies
run: bun install
- name: Install DB dependencies
working-directory: packages/db
run: bun install --frozen-lockfile --ignore-scripts

- name: Apply database migrations
env:
DATABASE_URL: ${{ secrets.DATABASE_URL_DEV }}
run: |
cd packages/db
bunx prisma migrate deploy
working-directory: packages/db
run: bunx prisma migrate deploy
10 changes: 5 additions & 5 deletions .github/workflows/database-migrations-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ jobs:
with:
bun-version: latest

- name: Install dependencies
run: bun install
- name: Install DB dependencies
working-directory: packages/db
run: bun install --frozen-lockfile --ignore-scripts

- name: Apply database migrations
env:
DATABASE_URL: ${{ secrets.DATABASE_URL_PROD }}
run: |
cd packages/db
bunx prisma migrate deploy
working-directory: packages/db
run: bunx prisma migrate deploy
8 changes: 5 additions & 3 deletions .github/workflows/trigger-tasks-deploy-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ jobs:
- name: Use Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: '22.x' # Updated to match Node.js w/ Vercel
node-version: "22.x" # Updated to match Node.js w/ Vercel
- name: Setup Bun
uses: oven-sh/setup-bun@v2
- name: Clear cache
run: rm -rf node_modules .bun
- name: Install dependencies
run: |
bun install
run: bun install --frozen-lockfile || bun install --frozen-lockfile --ignore-scripts
- name: Install DB package dependencies
working-directory: ./packages/db
run: bun install --frozen-lockfile --ignore-scripts
- name: Generate Prisma client
working-directory: ./packages/db
run: bunx prisma generate
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/trigger-tasks-deploy-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ jobs:
- name: Use Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: '20.x'
node-version: "20.x"

- name: Setup Bun
uses: oven-sh/setup-bun@v2

- name: Install dependencies
run: bun install
run: bun install --frozen-lockfile || bun install --frozen-lockfile --ignore-scripts

- name: Generate Prisma client
working-directory: ./packages/db
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ Start and initialize the PostgreSQL database using Docker:
1. Start the database:

```sh
cd packages/db
bun docker:up
```

Expand Down
29 changes: 16 additions & 13 deletions apps/app/src/jobs/tasks/task/policy-schedule.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { env } from '@/env.mjs';
import { db } from '@db';
import { Novu } from '@novu/api';
import { Novu } from '@novu/api';
import { logger, schedules } from '@trigger.dev/sdk';

export const policySchedule = schedules.task({
id: 'policy-schedule',
machine: 'large-1x',
cron: '0 */12 * * *', // Every 12 hours
maxDuration: 1000 * 60 * 10, // 10 minutes
run: async () => {
const now = new Date();

const novu = new Novu({
secretKey: process.env.NOVU_API_KEY
const novu = new Novu({
secretKey: process.env.NOVU_API_KEY,
});

// Find all published policies that have a review date and frequency set
Expand All @@ -32,7 +32,7 @@ export const policySchedule = schedules.task({
name: true,
members: {
where: {
role: { contains: 'owner' }
role: { contains: 'owner' },
},
select: {
user: {
Expand Down Expand Up @@ -123,15 +123,18 @@ export const policySchedule = schedules.task({
});

// Build array of recipients (org owner(s) and policy assignee(s)) for each overdue policy
const recipientsMap = new Map<string, {
email: string;
userId: string;
name: string;
policy: typeof overduePolicies[number];
}>();
const recipientsMap = new Map<
string,
{
email: string;
userId: string;
name: string;
policy: (typeof overduePolicies)[number];
}
>();
const addRecipients = (
users: Array<{ user: { id: string; email: string; name?: string } }>,
policy: typeof overduePolicies[number],
policy: (typeof overduePolicies)[number],
) => {
for (const entry of users) {
const user = entry.user;
Expand Down Expand Up @@ -178,7 +181,7 @@ export const policySchedule = schedules.task({
organizationId: recipient.policy.organizationId,
policyId: recipient.policy.id,
policyUrl: `${process.env.NEXT_PUBLIC_APP_URL ?? 'https://app.trycomp.ai'}/${recipient.policy.organizationId}/policies/${recipient.policy.id}`,
}
},
})),
});

Expand Down
30 changes: 16 additions & 14 deletions apps/app/src/jobs/tasks/task/task-schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import { logger, schedules } from '@trigger.dev/sdk';

export const taskSchedule = schedules.task({
id: 'task-schedule',
machine: 'large-1x',
cron: '0 */12 * * *', // Every 12 hours
maxDuration: 1000 * 60 * 10, // 10 minutes
run: async () => {
const now = new Date();
const novu = new Novu({
secretKey: process.env.NOVU_API_KEY
const novu = new Novu({
secretKey: process.env.NOVU_API_KEY,
});

// Find all Done tasks that have a review date and frequency set
Expand All @@ -30,7 +31,7 @@ export const taskSchedule = schedules.task({
name: true,
members: {
where: {
role: { contains: 'owner' }
role: { contains: 'owner' },
},
select: {
user: {
Expand Down Expand Up @@ -129,15 +130,18 @@ export const taskSchedule = schedules.task({
},
});

const recipientsMap = new Map<string, {
email: string;
userId: string;
name: string;
task: typeof overdueTasks[number];
}>();
const recipientsMap = new Map<
string,
{
email: string;
userId: string;
name: string;
task: (typeof overdueTasks)[number];
}
>();
const addRecipients = (
users: Array<{ user: { id: string; email: string; name?: string } }>,
task: typeof overdueTasks[number],
task: (typeof overdueTasks)[number],
) => {
for (const entry of users) {
const user = entry.user;
Expand All @@ -159,7 +163,7 @@ export const taskSchedule = schedules.task({
for (const task of overdueTasks) {
// Org owners
if (task.organization && Array.isArray(task.organization.members)) {
addRecipients(task.organization.members, task);
addRecipients(task.organization.members, task);
}
// Policy assignee
if (task.assignee) {
Expand All @@ -185,7 +189,7 @@ export const taskSchedule = schedules.task({
organizationId: recipient.task.organizationId,
taskId: recipient.task.id,
taskUrl: `${process.env.NEXT_PUBLIC_APP_URL ?? 'https://app.trycomp.ai'}/${recipient.task.organizationId}/tasks/${recipient.task.id}`,
}
},
})),
});

Expand Down Expand Up @@ -218,5 +222,3 @@ export const taskSchedule = schedules.task({
}
},
});


Loading
Loading