@tuturuuu/trigger
The@tuturuuu/trigger
package provides background job processing capabilities using Trigger.dev, enabling long-running tasks like calendar synchronization, batch operations, and scheduled workflows.
Installation
Available Jobs
Google Calendar Sync
The platform provides three types of calendar synchronization jobs:1. Full Sync
Complete synchronization of all calendar events.- Initial calendar setup
- Recovery from sync errors
- Manual refresh requested by user
2. Incremental Sync
Efficient delta synchronization using Google’s sync tokens.- Retrieves last sync token from
calendar_sync_states
- Fetches only changed events since last sync
- Updates database with changes
- Stores new sync token for next incremental sync
- Regular background sync (every 5-15 minutes)
- Webhook-triggered updates
- Real-time calendar updates
3. Batched Sync
Batch synchronization for multiple workspaces.- Scheduled background sync for all workspaces
- System-wide calendar refresh
- Admin-initiated bulk sync
Task Scheduling
Schedule tasks based on due dates and priorities.- Analyzes task due dates and priorities
- Finds available time slots in calendar
- Creates calendar events for high-priority tasks
- Respects work hours and existing commitments
Calendar Sync Implementation
Sync Coordination
The package uses atomic sync state management to prevent concurrent syncs:Full Sync Flow
Incremental Sync Flow
Scheduled Jobs
Daily Calendar Sync
Development
Local Development
Testing Jobs Locally
Deployment
Deploy Jobs to Production
Environment Variables
Required in.env
:
Monitoring
View Job Runs
Access the Trigger.dev dashboard to monitor:- Job execution history
- Success/failure rates
- Execution duration
- Error logs
- Retry attempts
Error Handling
Best Practices
✅ DO
-
Use appropriate sync types
-
Implement sync locks
-
Log sync operations
-
Set appropriate max durations
-
Handle token expiration
❌ DON’T
-
Don’t skip lock acquisition
-
Don’t use user client for background jobs
-
Don’t ignore sync errors
Related Documentation
Future Jobs
Potential background jobs to implement:- Email processing and AI summarization
- Batch task creation from templates
- Automated report generation
- Data export and backup
- Workspace analytics calculation