
Synchronize Validation Statuses with KoboToolbox
sync_validation_submissions.RdSynchronizes validation statuses between the local system and KoboToolbox by processing validation flags and updating submission statuses accordingly. This function respects manual human approvals and handles both flagged and clean submissions in parallel with rate limiting.
Usage
sync_validation_submissions(log_threshold = logger::DEBUG)Details
The function follows these steps:
Downloads the current validation flags from cloud storage
Sets up parallel processing using the future package (max 4 workers with rate limiting)
Fetches current validation status from KoboToolbox to identify manual approvals
Identifies manually approved submissions and preserves them (excludes system approvals)
Processes flagged submissions (marking as not approved), EXCLUDING manually approved ones
Processes clean submissions (marking as approved)
Combines validation statuses from updates and preserved manual approvals
Adds KoboToolbox validation status to validation flags
Pushes all validation flags with KoboToolbox status to MongoDB for record-keeping
Progress reporting is enabled to track the status of submissions being processed.
Note
This function requires proper configuration in the config file, including:
MongoDB connection parameters
KoboToolbox asset ID and token (configured under ingestion$kefs$koboform)
Google cloud storage parameters
Manual Approval Preservation
The function identifies submissions that have been manually approved by humans (validated_by is not empty and is not the system username) and preserves these approvals even if automated validation would flag them. Flagged submissions that were manually approved will NOT be marked as "not approved" by this function. This ensures human review decisions are always respected and never overwritten by the automated system.
Rate Limiting
To avoid overwhelming the KoboToolbox API server (kf.fimskenya.co.ke), the function limits parallel workers to 4 and adds a 200ms delay between requests. This provides approximately 20 requests per second across all workers while maintaining server stability. With this configuration, processing 13,000 submissions takes approximately 2-3 hours (including the initial status fetch to identify manual approvals).
Examples
if (FALSE) { # \dontrun{
# Run with default DEBUG logging
sync_validation_submissions()
# Run with INFO level logging
sync_validation_submissions(log_threshold = logger::INFO)
} # }