7.7 KiB
7.7 KiB
Partner Log Processing Migration Summary
This document summarizes the migration of partner data processing from the Job Worker to the Partner Sync Worker.
Changes Made
1. Job Worker (workers/job_worker.js)
Removed:
- Partner log file processing logic (
.logfile detection and processing) readPartnerLogFile()functionDATA_SATLOC_LOGcase from file processing switch statement- Direct SatLoc log parsing capability
Added:
- Partner queue configuration (
partnerQueueconstant) enqueuePartnerDataFile()function to send partner files to partner sync worker- Partner log file detection that enqueues files instead of processing them
PARTNER_LOGtype classification for detected.logfiles- New case in file processing switch to handle partner log files by enqueuing them
- Import of
PartnerTasksconstants
Modified:
- File classification logic to separate partner log files from regular data files
- Data file filtering to exclude partner log files from normal processing
2. Partner Sync Worker (workers/partner_sync_worker.js)
Added:
PROCESS_PARTNER_DATA_FILEtask type handling in main task processing switchprocessPartnerDataFile()function with comprehensive partner data file processing- SatLoc binary log parsing capability using
SatLocLogParser - Application detail batch insertion for performance
- ApplicationFile and Application status updates after processing
- Error handling and cleanup for temporary files
- Processing duration tracking and logging
3. Constants (helpers/constants.js)
Added:
PROCESS_PARTNER_DATA_FILEtoPartnerTasksenum
4. File Constants (helpers/file_constants.js)
Removed:
DATA_SATLOC_LOGconstant (no longer needed in job worker context)
5. Documentation
Updated:
PARTNER_LOG_FILE_PROCESSING.mdwith new architecture and process flow- Added
PARTNER_LOG_MIGRATION_SUMMARY.md(this file)
Architecture Changes
Before Migration
Job Upload → Job Worker → (detects .log files) → SatLoc Parser → Application Details
After Migration
Job Upload → Job Worker → (detects .log files) → Partner Queue → Partner Sync Worker → SatLoc Parser → Application Details
Benefits of Migration
1. Separation of Concerns
- Job Worker focuses on core job file processing (AgNav, SHAPE, SATLOG files)
- Partner Sync Worker specializes in partner-specific data processing
- Clear boundary between general job processing and partner integration
2. Scalability
- Partner data processing can be scaled independently
- Partner Sync Worker can be deployed on different infrastructure if needed
- Queue-based processing allows for better load management
3. Maintainability
- Partner-specific logic is centralized in partner sync worker
- Easier to add new partner file formats without modifying job worker
- Cleaner codebase with focused responsibilities
4. Reliability
- Partner file processing failures don't affect main job processing
- Better error handling and retry capabilities through queue system
- Asynchronous processing prevents blocking of job imports
5. Extensibility
- Easy to add new partner types and file formats
- Partner-specific configuration and processing logic isolated
- Can support different processing strategies per partner
Process Flow
1. Job Import with Partner Files
- User uploads job with mixed file types (
.t01,.dbf,.log, etc.) - Job Worker extracts and classifies all files
- Regular files (AgNav, SHAPE, SATLOG) processed immediately
- Partner log files (
.log) enqueued to Partner Sync Worker - ApplicationFile records created for all files
- Job processing completes normally
2. Partner File Processing
- Partner Sync Worker receives
PROCESS_PARTNER_DATA_FILEtask - Determines file type and selects appropriate parser
- For
.logfiles, uses SatLoc binary parser - Extracts application details and statistics
- Saves data using batch insertion for performance
- Updates ApplicationFile and Application status
- Cleans up temporary files and logs results
Queue Message Format
{
type: 'process_partner_data_file',
data: {
filePath: '/path/to/uploaded/file.log',
fileId: 'mongodb_application_file_id',
applicationId: 'mongodb_application_id',
fileName: 'original_filename.log',
enqueuedAt: '2025-08-27T10:30:00.000Z'
}
}
Error Handling
Job Worker
- If enqueuing fails, logs error but continues with other files
- Application file record is still created for tracking
- Partner file processing can be retried manually if needed
Partner Sync Worker
- Comprehensive error handling with proper logging
- Updates ApplicationFile with error status on failure
- Temporary file cleanup in all scenarios
- Processing duration tracking for monitoring
Testing
Validation Steps
- Syntax Check: All modified files compile without errors
- Integration Test: Partner log files are properly enqueued during job import
- Processing Test: Partner Sync Worker correctly processes enqueued log files
- Data Verification: Application details are correctly saved and application status updated
Test Commands
# Syntax validation
node -c workers/job_worker.js
node -c workers/partner_sync_worker.js
node -c helpers/constants.js
node -c helpers/file_constants.js
# Integration testing would require:
# 1. Upload job with .log files
# 2. Verify files are enqueued to partner queue
# 3. Verify partner sync worker processes files
# 4. Verify application details are saved correctly
Backward Compatibility
- No breaking changes to existing job processing
- Regular data files (AgNav, SHAPE, SATLOG) processed identically
- API endpoints and user interface unchanged
- Existing applications and jobs unaffected
Future Enhancements
Possible Improvements
- Partner Type Detection: Automatic partner detection from filename patterns
- Multiple Parser Support: Support for different partner file formats beyond SatLoc
- Real-time Processing Status: WebSocket updates for partner file processing progress
- Batch Processing: Process multiple partner files in a single task
- Partner-specific Configuration: Per-partner processing options and validation rules
Adding New Partner Types
- Add partner-specific parser to partner sync worker
- Update file extension detection logic
- Add partner configuration to
partner_config.js - Test with sample partner files
Migration Verification
Checklist
- Partner log files no longer processed by Job Worker
- Partner log files properly enqueued to Partner Sync Worker
- Partner Sync Worker processes SatLoc
.logfiles correctly - Application details saved with batch insertion
- ApplicationFile and Application status updated properly
- Error handling implemented throughout
- Documentation updated
- All syntax checks pass
- No breaking changes to existing functionality
Deployment Notes
Prerequisites
- Partner Sync Worker must be running and connected to message queue
- Partner queue (
dev_partner_tasksorpartner_tasks) must be accessible - Database permissions for ApplicationDetail insertMany operations
Monitoring
- Monitor partner queue depth for processing backlog
- Track processing duration in logs for performance
- Watch for partner file processing errors in partner sync worker logs
- Verify ApplicationFile records are being updated correctly
Rollback Strategy
If issues arise, the migration can be rolled back by:
- Reverting Job Worker changes to process
.logfiles directly - Disabling partner file enqueuing
- Processing any queued partner files manually
- The data model changes are minimal and backward compatible