feat: support scan by time window - #18
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat: Support scan by time window
Summary
Adds support for scheduled time-based control of blockchain event scanning in development environments. This feature allows configuring specific time windows when scanning should be enabled or disabled, helping reduce resource usage during off-hours in non-production environments.
Cost Benefits: By disabling scanning during off-hours, this feature significantly reduces the number of requests to blockchain nodes, thereby lowering costs for node service providers (e.g., Infura, Alchemy) when running in development environments.
Changes
New Features
schedule-pattern-parser.ts): Parses schedule pattern strings with timezone and day-specific time rangesschedule-evaluator.ts): Evaluates whether scanning should be enabled at a given UTC time based on the parsed scheduleschedule_scan_control.job.ts): Command-line job that checks the current time against the schedule and updates network scan states accordinglyService Enhancements
updateAllNetworksStopScan()method to bulk updateis_stop_scanflag for all networksdeleteAllProcessedBlocks()method to clear processed block records when resuming scansNetworkServiceto make it available for dependency injection in job modulesDocumentation
README.mdcovering:Technical Details
Schedule Pattern Format
+HH:MMor-HH:MMformat (e.g.,+07:00,-05:00)mon,tue,wed,thu,fri,sat,sun(case-insensitive)HH:MM-HH:MM(24-hour format)all(scan all day),off(disable scanning)Behavior
ProcessedBlockEntityrecords are deleted to ensure fresh start from current blockchain stateis_stop_scan = truefor all networksJob Execution
The job is designed to run periodically (e.g., via Kubernetes CronJob) and:
Cost Optimization
Reduced Node Service Costs: This feature helps minimize costs in development environments by:
eth_getBlockByNumber,eth_getLogs)Example: If scanning is configured for business hours only (8am-6pm, Mon-Fri), this reduces node service requests by approximately 58% compared to 24/7 scanning (10 hours/day × 5 days = 50 hours/week vs 168 hours/week).
Usage Examples
Testing
Notes