Skip to content

Set up Background sync using Trigger.dev #3092

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Jun 17, 2025
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
6e73298
feat: queue task for trial
DennieDan Jun 14, 2025
cb01720
style: apply prettier formatting
DennieDan Jun 14, 2025
c8a8b01
style: apply prettier formatting for feat/setup-trigger (#3093)
DennieDan Jun 15, 2025
64b3b5e
fix: remove unused code
DennieDan Jun 15, 2025
a94c3b1
Merge remote-tracking branch 'origin/feat/setup-trigger'
DennieDan Jun 15, 2025
5ebbe46
fix: connect local dev to server for running queued tasks
DennieDan Jun 15, 2025
639f129
feat: create scheduled background task
DennieDan Jun 15, 2025
f9f3755
feat: define google fetching function
DennieDan Jun 16, 2025
42bca59
feat: add background sync from google to tuturuuu
DennieDan Jun 16, 2025
4584f75
feat: setup trigger for Google Calendar sync
DennieDan Jun 16, 2025
4d4de39
chore: add .env.example in root directory
DennieDan Jun 16, 2025
2f3b2af
chore: move .env.local to packages/trigger/
DennieDan Jun 17, 2025
49978b8
feat: add changes using cursor
DennieDan Jun 17, 2025
2d4a1e9
fix: export example.ts task
DennieDan Jun 17, 2025
a002eaa
feat: add current view within background sync range check
DennieDan Jun 17, 2025
70e3e99
fix: export example.ts instead of google.ts
DennieDan Jun 17, 2025
ef6cbfa
fix: fix to 4 weeks start from current week not from now
DennieDan Jun 17, 2025
555e347
chore: merge with feat/setup-trigger
DennieDan Jun 17, 2025
8747e54
chore(trigger): move .env.example to the trigger package
vhpx Jun 17, 2025
a99909f
Merge branch 'main' into feat/setup-trigger
vhpx Jun 17, 2025
d419d5c
chore(db): consolidate database schema
vhpx Jun 17, 2025
ae47ade
chore(db): update database schema with new types and argument order a…
vhpx Jun 17, 2025
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
43 changes: 43 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Required environment variables
# for both development and production
NEXT_PUBLIC_SUPABASE_URL=YOUR_SUPABASE_URL
NEXT_PUBLIC_SUPABASE_ANON_KEY=YOUR_SUPABASE_ANON_KEY
SUPABASE_SERVICE_KEY=YOUR_SUPABASE_SERVICE_KEY

# Optional API keys
OPENAI_API_KEY=YOUR_OPENAI_API_KEY
ANTHROPIC_API_KEY=YOUR_ANTHROPIC_API_KEY
GOOGLE_GENERATIVE_AI_API_KEY=YOUR_GOOGLE_GENERATIVE_AI_API_KEY

# Google Vertex AI credentials
GOOGLE_VERTEX_PROJECT=YOUR_GOOGLE_VERTEX_PROJECT
GOOGLE_VERTEX_LOCATION=YOUR_GOOGLE_VERTEX_LOCATION
GOOGLE_APPLICATION_CREDENTIALS=YOUR_GOOGLE_APPLICATION_CREDENTIALS

# Google Calendar API credentials
GOOGLE_CLIENT_ID=YOUR_GOOGLE_CLIENT_ID
GOOGLE_CLIENT_SECRET=YOUR_GOOGLE_CLIENT_SECRET
GOOGLE_REDIRECT_URI=YOUR_GOOGLE_REDIRECT_URI

# AWS Credentials
AWS_REGION=YOUR_AWS_REGION
AWS_ACCESS_KEY_ID=YOUR_AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY=YOUR_AWS_SECRET
SOURCE_NAME=YOUR_SOURCE_NAME
SOURCE_EMAIL=YOUR_SOURCE_EMAIL

DEEPGRAM_ENV=YOUR_DEEPGRAM_ENV
DEEPGRAM_API_KEY=YOUR_DEEPGRAM_API_KEY

MODAL_TOKEN_ID=YOUR_MODAL_TOKEN_ID
MODAL_TOKEN_SECRET=YOUR_MODAL_TOKEN_SECRET

CF_ACCOUNT_ID=YOUR_CF_ACCOUNT_ID
CF_API_TOKEN=YOUR_CF_API_TOKEN

# Infrastructure Credentials
SCRAPER_URL=YOUR_SCRAPER_URL
AURORA_EXTERNAL_URL=YOUR_AURORA_EXTERNAL_URL
AURORA_EXTERNAL_WSID=YOUR_AURORA_EXTERNAL_WSID
PROXY_API_KEY=YOUR_PROXY_API_KEY
NEXT_PUBLIC_PROXY_API_KEY=YOUR_NEXT_PUBLIC_PROXY_API_KEY
10 changes: 8 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ dist
# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env
.env.local
.env.development.local
.env.test.local
Expand All @@ -38,4 +38,10 @@ yarn-error.log*

# Typescript
*.tsbuildinfo
next-env.d.ts
next-env.d.ts
.trigger.env
.env.local
.env.*.local

# Trigger.dev
.trigger/
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
-- Create table to coordinate calendar sync operations
create table "public"."workspace_calendar_sync_coordination" (
"ws_id" uuid not null,
"last_upsert" timestamp with time zone not null default now(),
"created_at" timestamp with time zone default now(),
"updated_at" timestamp with time zone default now()
);

-- Add primary key
alter table "public"."workspace_calendar_sync_coordination"
add constraint "workspace_calendar_sync_coordination_pkey" PRIMARY KEY (ws_id);

-- Add foreign key to workspaces
alter table "public"."workspace_calendar_sync_coordination"
add constraint "workspace_calendar_sync_coordination_ws_id_fkey"
FOREIGN KEY (ws_id) REFERENCES workspaces(id) ON DELETE CASCADE;

-- Enable RLS
alter table "public"."workspace_calendar_sync_coordination" enable row level security;

-- Create policy for workspace members
create policy "Enable access for workspace members" on "public"."workspace_calendar_sync_coordination"
as permissive for all to authenticated using (
EXISTS (
SELECT 1 FROM workspace_members
WHERE workspace_members.ws_id = workspace_calendar_sync_coordination.ws_id
AND workspace_members.user_id = auth.uid()
)
) with check (
EXISTS (
SELECT 1 FROM workspace_members
WHERE workspace_members.ws_id = workspace_calendar_sync_coordination.ws_id
AND workspace_members.user_id = auth.uid()
)
);

-- Create function to update the updated_at timestamp
CREATE OR REPLACE FUNCTION update_workspace_calendar_sync_coordination_updated_at()
RETURNS TRIGGER AS $$
BEGIN
NEW.updated_at = now();
RETURN NEW;
END;
$$ LANGUAGE plpgsql;

-- Create trigger to automatically update updated_at
CREATE TRIGGER update_workspace_calendar_sync_coordination_updated_at
BEFORE UPDATE ON workspace_calendar_sync_coordination
FOR EACH ROW
EXECUTE FUNCTION update_workspace_calendar_sync_coordination_updated_at();

-- Enable audit tracking
select audit.enable_tracking('public.workspace_calendar_sync_coordination'::regclass);
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@
}
};

const triggerHelloWorld = async () => {
const res = await fetch('/api/hello-world');
const data = await res.json();
console.log(data);
};

Check warning on line 62 in apps/web/src/app/[locale]/(dashboard)/[wsId]/calendar/active-sync.tsx

View check run for this annotation

Codecov / codecov/patch

apps/web/src/app/[locale]/(dashboard)/[wsId]/calendar/active-sync.tsx#L57-L62

Added lines #L57 - L62 were not covered by tests
return (
<div>
<div className="mb-4 flex gap-2">
Expand Down Expand Up @@ -85,6 +91,7 @@
>
Switch to month
</Button>
<Button onClick={() => triggerHelloWorld()}>Trigger Hello World</Button>

Check warning on line 94 in apps/web/src/app/[locale]/(dashboard)/[wsId]/calendar/active-sync.tsx

View check run for this annotation

Codecov / codecov/patch

apps/web/src/app/[locale]/(dashboard)/[wsId]/calendar/active-sync.tsx#L94

Added line #L94 was not covered by tests
</div>

{/* Add sync progress bar when syncing */}
Expand Down
16 changes: 16 additions & 0 deletions apps/web/src/app/api/hello-world/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import { tasks } from '@trigger.dev/sdk/v3';

Check warning on line 2 in apps/web/src/app/api/hello-world/route.ts

View check run for this annotation

Codecov / codecov/patch

apps/web/src/app/api/hello-world/route.ts#L2

Added line #L2 was not covered by tests
import type { helloWorldTask } from '@tuturuuu/trigger/example';
import { NextResponse } from 'next/server';

Check warning on line 4 in apps/web/src/app/api/hello-world/route.ts

View check run for this annotation

Codecov / codecov/patch

apps/web/src/app/api/hello-world/route.ts#L4

Added line #L4 was not covered by tests

//tasks.trigger also works with the edge runtime
//export const runtime = "edge";

export async function GET() {
const handle = await tasks.trigger<typeof helloWorldTask>(
'hello-world',
'James'
);

Check warning on line 13 in apps/web/src/app/api/hello-world/route.ts

View check run for this annotation

Codecov / codecov/patch

apps/web/src/app/api/hello-world/route.ts#L9-L13

Added lines #L9 - L13 were not covered by tests

return NextResponse.json(handle);
}

Check warning on line 16 in apps/web/src/app/api/hello-world/route.ts

View check run for this annotation

Codecov / codecov/patch

apps/web/src/app/api/hello-world/route.ts#L15-L16

Added lines #L15 - L16 were not covered by tests
Loading