Some checks are pending
Bidi Control Character Guard / bidi-control-guard (push) Waiting to run
Circular Dependency Check / Check for new circular dependencies (push) Waiting to run
Citus Migration Smoke / Combined migrations on single-node Citus (push) Waiting to run
E2E Fresh Install Tests / fresh-install-e2e (push) Waiting to run
ext-v2 guardrails / Run ext-v2 guard and ESLint (push) Waiting to run
Integration Tests / Check for relevant changes (push) Waiting to run
Integration Tests / ${{ (github.event_name == 'schedule' || github.event.inputs.suite == 'full') && 'Full integration suite' || 'Tier-1 integration subset' }} (push) Blocked by required conditions
Mobile checks / Mobile lint + typecheck (push) Waiting to run
Mobile checks / Mobile unit tests (push) Waiting to run
Mobile checks / Mobile dependency audit (report) (push) Waiting to run
Mobile checks / Mobile reproducibility checks (push) Waiting to run
Secrets guard (env backups) / Ensure no tracked env backup files (push) Waiting to run
Temporal Readiness / fast-readiness (push) Waiting to run
Temporal Readiness / docker-parity (push) Waiting to run
TypeScript Type Check / Nx affected typecheck (push) Waiting to run
Unit Tests / Skipped-test budget (push) Waiting to run
Unit Tests / Nx affected unit tests (push) Waiting to run
Unit Tests / Server unit coverage (informational) (push) Waiting to run
Validate Tenant Management Schema / Check for relevant changes (push) Waiting to run
Validate Tenant Management Schema / Validate Tenant Management Schema (push) Blocked by required conditions
EE Workflows Build Guard / ee-workflows-build-guard (push) Waiting to run
Excluded: .git, node_modules, secrets/, compose.env, assemblyscript tgz Source: /opt/alga-psa on psa.joliet.tech
5.3 KiB
5.3 KiB
Scheduling System
Overview
The scheduling system provides a comprehensive solution for managing appointments, technician dispatch, and recurring events. It supports multiple agent assignments per schedule entry while maintaining efficient storage and performance characteristics.
Key Components
Database Structure
-
schedule_entries table:
- Core fields: entry_id, title, scheduled_start, scheduled_end, work_item_id, status
- Recurrence support: recurrence_pattern (JSONB), original_entry_id, is_recurring
- Multi-tenant: tenant field with RLS policies
- Work item integration: work_item_type, work_item_id for linking to tickets/tasks
-
schedule_entry_assignees table:
- Many-to-many relationship for multiple agent assignments
- Fields: tenant, entry_id, user_id
- Cascading deletes for data consistency
- Foreign key constraints to both users and schedule_entries
Core Files
-
Models:
@: Core scheduling logicserver/src/interfaces/schedule.interfaces.ts: TypeScript interfacesserver/src/lib/schemas/scheduleSchemas.ts: Zod validation schemas
-
UI Components:
server/src/components/time-management/ScheduleCalendar.tsx: Main calendar viewserver/src/components/time-management/EntryPopup.tsx: Entry creation/editingserver/src/components/ui/MultiUserPicker.tsx: Agent selection component
-
Actions:
server/src/lib/actions/scheduleActions.ts: Server actions for CRUD operations
Features
Multiple Agent Assignment
- Support for assigning multiple technicians/agents to a single schedule entry
- Role-based access control for multi-agent assignment capability
- Backward compatibility with legacy single-user assignments
- Efficient querying through proper database indexing
Recurrence Handling
-
Efficient storage of recurring events:
- Only master entries stored in database
- Virtual instances generated on-demand
- No duplicate storage for recurring instances
- Supports infinite recurrence patterns
-
Recurrence Patterns:
- Frequencies: daily, weekly, monthly, yearly
- Pattern options: interval, end date/count, exceptions
- Support for complex patterns (e.g., every 2 weeks on Monday and Wednesday)
-
Exception Handling:
- Single instance modifications
- Future occurrence updates
- All occurrence updates
- Pattern-based exceptions
Calendar Interface
- Interactive calendar with drag-and-drop support
- Multiple view options (day, week, month)
- Visual distinction between different work item types
- Real-time updates and conflict detection
- Responsive design for various screen sizes
Performance Optimizations
- Efficient database queries using proper indexes
- On-demand calculation of recurring instances
- Minimal storage overhead for recurring entries
- Optimized user assignment queries
Usage Examples
Creating a Schedule Entry
const entry = await ScheduleEntry.create({
title: "Site Visit",
scheduled_start: new Date("2024-01-15T10:00:00"),
scheduled_end: new Date("2024-01-15T12:00:00"),
work_item_id: "ticket_123",
work_item_type: "ticket",
status: "scheduled"
}, {
assignedUserIds: ["user1", "user2"] // Multiple agents
});
Creating a Recurring Entry
const recurringEntry = await ScheduleEntry.create({
// ... basic entry fields ...
recurrence_pattern: {
frequency: "weekly",
interval: 2,
daysOfWeek: [1, 3], // Monday and Wednesday
startDate: new Date("2024-01-15"),
endDate: new Date("2024-06-15")
}
});
Updating Assignments
await ScheduleEntry.update(entryId, {
assigned_user_ids: ["user1", "user2", "user3"]
}, "future"); // Updates this and future occurrences
Best Practices
-
Recurrence Patterns:
- Use appropriate frequency for the use case
- Consider time zone implications
- Set reasonable end dates or occurrence counts
- Handle exceptions appropriately
-
Multiple Assignments:
- Verify agent availability before assignment
- Consider workload distribution
- Maintain clear assignment hierarchy
- Handle conflicts gracefully
-
Performance:
- Query within reasonable date ranges
- Use appropriate indexes
- Handle large result sets properly
- Cache frequently accessed data
-
UI Considerations:
- Provide clear visual feedback
- Handle loading states gracefully
- Implement proper error handling
- Ensure responsive design
Security Considerations
-
Access Control:
- Role-based permissions for multi-agent assignment
- Tenant isolation through RLS
- Proper validation of user assignments
- Audit logging of changes
-
Data Integrity:
- Transaction handling for complex operations
- Validation of recurrence patterns
- Proper error handling and rollback
- Consistent state management
Future Enhancements
-
Advanced Scheduling:
- Resource conflict detection
- Automated scheduling optimization
- Complex recurrence patterns
- Calendar sync integration
-
Integration:
- External calendar system sync
- Mobile app support
- Real-time updates
- API expansion
-
Analytics:
- Schedule optimization insights
- Resource utilization tracking
- Pattern analysis
- Performance metrics
-
UI/UX:
- Enhanced drag-and-drop
- Better visualization options
- Improved mobile experience
- Accessibility enhancements