Jobs & Scheduling
PBS Knowledge uses a job queue system (BullMQ) to handle background tasks like data synchronization, email sending, and scheduled maintenance.
Overview
What Are Jobs?
Jobs are background tasks that:
- Run asynchronously without blocking users
- Process large amounts of data
- Execute on schedules
- Retry on failure
Job Types
| Queue | Purpose |
|---|---|
EMAIL_QUEUE | Sending transactional emails |
SYNC_QUEUE | Data synchronization tasks |
PUBLICATION_SYNC_QUEUE | Publication import/updates |
BACKUP_QUEUE | Database backups |
Viewing Jobs
Job Dashboard
- Go to Admin → System → Jobs
- See job queues and status
- View recent job history
- Monitor active jobs
Job Status
| Status | Meaning |
|---|---|
waiting | Queued, not yet started |
active | Currently processing |
completed | Successfully finished |
failed | Error occurred |
delayed | Scheduled for later |
paused | Queue is paused |
Job Details
Click any job to see:
- Job ID and type
- Input data
- Start and end times
- Duration
- Error messages (if failed)
- Retry attempts
Scheduled Jobs
Current Schedules
View scheduled jobs:
- Go to Admin → System → Schedulers
- See all scheduled tasks
- View next run times
- Check schedule patterns
Common Schedules
| Job | Default Schedule | Purpose |
|---|---|---|
| Publication Sync | Daily 2 AM | Import new publications |
| Citation Update | Weekly Sunday | Update citation counts |
| Dartmouth Sync | Daily 3 AM | Sync people/courses |
| Database Backup | Daily 4 AM | Backup database |
| Cleanup | Weekly | Remove old job data |
Cron Patterns
Schedules use cron syntax:
┌────────────── minute (0-59)
│ ┌──────────── hour (0-23)
│ │ ┌────────── day of month (1-31)
│ │ │ ┌──────── month (1-12)
│ │ │ │ ┌────── day of week (0-6, Sunday=0)
│ │ │ │ │
* * * * *
Examples:
0 2 * * * = Daily at 2:00 AM
0 0 * * 0 = Weekly on Sunday at midnight
0 */6 * * * = Every 6 hours
30 8 1 * * = Monthly on the 1st at 8:30 AM
Managing Schedulers
Creating a Scheduler
- Go to Admin → Schedulers
- Click Create Scheduler
- Configure:
- Name
- Job type
- Cron pattern
- Job data
- Active status
- Save
Editing Schedules
- Find the scheduler
- Click Edit
- Modify schedule or parameters
- Save changes
Pausing Schedules
To temporarily stop:
- Find the scheduler
- Click Pause
- Jobs won't run until resumed
- Click Resume to restart
Manual Job Execution
Running Jobs Manually
Trigger a job immediately:
- Go to Admin → Jobs
- Find the job type
- Click Run Now
- Optionally provide parameters
- Monitor execution
Use Cases
Manual runs are useful for:
- Testing new configurations
- Recovering from failures
- Immediate data updates
- Troubleshooting
Job Configuration
Queue Settings
Configure queue behavior:
- Concurrency - Parallel job limit
- Rate Limit - Jobs per time period
- Retry Policy - Failure handling
- Timeout - Maximum execution time
Retry Configuration
{
attempts: 3, // Number of retries
backoff: {
type: 'exponential', // Backoff strategy
delay: 1000 // Initial delay (ms)
}
}
Priority
Jobs can have priorities:
- Higher priority runs first
- Default priority is 0
- Lower numbers = higher priority
Monitoring
Health Indicators
Monitor job system health:
- Queue length (waiting jobs)
- Processing rate
- Failure rate
- Average duration
Alerts
Configure alerts for:
- Queue backup (too many waiting)
- High failure rate
- Long-running jobs
- System errors
Metrics Dashboard
View metrics:
- Go to Admin → System → Metrics
- See job statistics
- View trends over time
- Identify bottlenecks
Troubleshooting
Jobs Not Running
- Check Redis connectivity
- Verify worker is running
- Check scheduler is active
- Review error logs
Jobs Failing
- Check job error message
- Verify external service status
- Check rate limits
- Review input data
Queue Backup
If jobs are piling up:
- Check worker capacity
- Increase concurrency if possible
- Pause non-critical jobs
- Address failed jobs blocking queue
Clearing Stuck Jobs
To clear problematic jobs:
- Go to job queue
- Select stuck jobs
- Click Remove or Retry
- Monitor queue recovery
Best Practices
Schedule Timing
- Run heavy jobs during off-hours
- Stagger schedules to avoid conflicts
- Allow buffer between dependent jobs
Error Handling
- Configure appropriate retry policies
- Monitor failure rates
- Set up alerting
- Document recovery procedures
Performance
- Keep job payloads small
- Use appropriate concurrency
- Monitor queue lengths
- Scale workers as needed