Skip to content

Commit

Permalink
Use default interval to stagger new jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
johannaengland committed Aug 8, 2024
1 parent c7b7cb1 commit a3300ec
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog.d/337.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use default interval from pollfile to stagger new jobs
7 changes: 4 additions & 3 deletions src/zino/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,11 @@ def init_state_for_devices(devices: Sequence[PollDevice]):
async def load_and_schedule_polldevs(polldevs_conf: str):
new_devices, deleted_devices, changed_devices, defaults = load_polldevs(polldevs_conf)
deschedule_devices(deleted_devices | changed_devices)
schedule_devices(new_devices | changed_devices)
stagger_interval = defaults.get("interval", DEFAULT_INTERVAL_MINUTES)
schedule_devices(new_devices | changed_devices, int(stagger_interval))


def schedule_devices(devices: Sequence[str]):
def schedule_devices(devices: Sequence[str], stagger_interval: int = DEFAULT_INTERVAL_MINUTES):
devices = sorted((state.polldevs[name] for name in devices), key=operator.attrgetter("priority"), reverse=True)
if not devices:
return
Expand All @@ -94,7 +95,7 @@ def schedule_devices(devices: Sequence[str]):
scheduler = get_scheduler()

# Spread poll jobs evenly across the entire default interval
stagger_factor = (DEFAULT_INTERVAL_MINUTES * 60) / len(devices)
stagger_factor = (stagger_interval * 60) / len(devices)
for index, device in enumerate(devices):
first_run_time = datetime.now() + timedelta(seconds=index * stagger_factor)

Expand Down

0 comments on commit a3300ec

Please sign in to comment.