feat(poll_scheduler): add cron-based poll scheduling to all connectors#2080
Open
apachler wants to merge 1 commit intothingsboard:masterfrom
Open
feat(poll_scheduler): add cron-based poll scheduling to all connectors#2080apachler wants to merge 1 commit intothingsboard:masterfrom
apachler wants to merge 1 commit intothingsboard:masterfrom
Conversation
Introduce PollScheduler, a new utility that accepts one or more cron expressions (via croniter) and computes the next monotonic poll time. The helper function compute_next_poll() provides a single drop-in replacement for the existing "current_time + poll_period" pattern used across every connector. - Add thingsboard_gateway/tb_utility/poll_scheduler.py with PollScheduleEntry, PollScheduler, and compute_next_poll() - Add unit tests in tests/unit/test_poll_scheduler.py - Integrate PollScheduler into all connectors: bacnet, ble, can, ftp, modbus, odbc, opcua, request, snmp - Add pollSchedule: null placeholder to all connector config examples - Add croniter>=1.3.8 to requirements.txt and setup.py dependencies When pollSchedule is null or absent the behaviour is unchanged (pollPeriod is used as before). When a cron schedule is supplied the next fire time is derived from the schedule instead.
Contributor
|
Hi @apachler, thanks for your contribution! |
Contributor
Author
|
Hi @samson0v, sure, let me know what you need from me ;) |
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.
Add cron-based
pollSchedulesupport for all connectorsWhat
Adds an optional
pollScheduleparameter that accepts cron expressions to control poll timing. This enables wall-clock-aligned polling (e.g. exactly at :00, :05, :10) and time-dependent schedules (e.g. faster polling during production, slower on weekends).Also fixes a missing
pollPerioddefault in the Modbus Slave connector (config['pollPeriod']→config.get('pollPeriod', 5000)), which is the only connector that crashes whenpollPeriodis omitted.Configuration
pollScheduletakes precedence overpollPeriodwhen present. A value ofnull(or omitting the key entirely) keeps the originalpollPeriodbehavior unchanged.Changes
thingsboard_gateway/tb_utility/poll_scheduler.py—PollScheduler,PollScheduleEntry,compute_next_poll()croniter>=1.3.8(depends only onpython-dateutil, already in the tree)connectors/modbus/slave.py— add missingpollPerioddefault (5000ms)PollSchedulerfrom config, usecompute_next_poll()instead ofmonotonic() + poll_periodBreaking changes
None.