217 lines
7.7 KiB
Markdown
217 lines
7.7 KiB
Markdown
# 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 (`.log` file detection and processing)
|
|
- `readPartnerLogFile()` function
|
|
- `DATA_SATLOC_LOG` case from file processing switch statement
|
|
- Direct SatLoc log parsing capability
|
|
|
|
**Added:**
|
|
- Partner queue configuration (`partnerQueue` constant)
|
|
- `enqueuePartnerDataFile()` function to send partner files to partner sync worker
|
|
- Partner log file detection that enqueues files instead of processing them
|
|
- `PARTNER_LOG` type classification for detected `.log` files
|
|
- New case in file processing switch to handle partner log files by enqueuing them
|
|
- Import of `PartnerTasks` constants
|
|
|
|
**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_FILE` task type handling in main task processing switch
|
|
- `processPartnerDataFile()` 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_FILE` to `PartnerTasks` enum
|
|
|
|
### 4. File Constants (`helpers/file_constants.js`)
|
|
|
|
**Removed:**
|
|
- `DATA_SATLOC_LOG` constant (no longer needed in job worker context)
|
|
|
|
### 5. Documentation
|
|
|
|
**Updated:**
|
|
- `PARTNER_LOG_FILE_PROCESSING.md` with 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
|
|
1. User uploads job with mixed file types (`.t01`, `.dbf`, `.log`, etc.)
|
|
2. Job Worker extracts and classifies all files
|
|
3. Regular files (AgNav, SHAPE, SATLOG) processed immediately
|
|
4. Partner log files (`.log`) enqueued to Partner Sync Worker
|
|
5. ApplicationFile records created for all files
|
|
6. Job processing completes normally
|
|
|
|
### 2. Partner File Processing
|
|
1. Partner Sync Worker receives `PROCESS_PARTNER_DATA_FILE` task
|
|
2. Determines file type and selects appropriate parser
|
|
3. For `.log` files, uses SatLoc binary parser
|
|
4. Extracts application details and statistics
|
|
5. Saves data using batch insertion for performance
|
|
6. Updates ApplicationFile and Application status
|
|
7. Cleans up temporary files and logs results
|
|
|
|
## Queue Message Format
|
|
|
|
```javascript
|
|
{
|
|
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
|
|
1. **Syntax Check**: All modified files compile without errors
|
|
2. **Integration Test**: Partner log files are properly enqueued during job import
|
|
3. **Processing Test**: Partner Sync Worker correctly processes enqueued log files
|
|
4. **Data Verification**: Application details are correctly saved and application status updated
|
|
|
|
### Test Commands
|
|
```bash
|
|
# 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
|
|
1. **Partner Type Detection**: Automatic partner detection from filename patterns
|
|
2. **Multiple Parser Support**: Support for different partner file formats beyond SatLoc
|
|
3. **Real-time Processing Status**: WebSocket updates for partner file processing progress
|
|
4. **Batch Processing**: Process multiple partner files in a single task
|
|
5. **Partner-specific Configuration**: Per-partner processing options and validation rules
|
|
|
|
### Adding New Partner Types
|
|
1. Add partner-specific parser to partner sync worker
|
|
2. Update file extension detection logic
|
|
3. Add partner configuration to `partner_config.js`
|
|
4. Test with sample partner files
|
|
|
|
## Migration Verification
|
|
|
|
### Checklist
|
|
- [x] Partner log files no longer processed by Job Worker
|
|
- [x] Partner log files properly enqueued to Partner Sync Worker
|
|
- [x] Partner Sync Worker processes SatLoc `.log` files correctly
|
|
- [x] Application details saved with batch insertion
|
|
- [x] ApplicationFile and Application status updated properly
|
|
- [x] Error handling implemented throughout
|
|
- [x] Documentation updated
|
|
- [x] All syntax checks pass
|
|
- [x] No breaking changes to existing functionality
|
|
|
|
## Deployment Notes
|
|
|
|
### Prerequisites
|
|
- Partner Sync Worker must be running and connected to message queue
|
|
- Partner queue (`dev_partner_tasks` or `partner_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:
|
|
1. Reverting Job Worker changes to process `.log` files directly
|
|
2. Disabling partner file enqueuing
|
|
3. Processing any queued partner files manually
|
|
4. The data model changes are minimal and backward compatible
|