Skip to content

Commit e1f4b35

Browse files
committed
Un-align jobs to avoid them firing all at once
1 parent ec2254e commit e1f4b35

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

Pipfile.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

netflowbot.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@
2626

2727

2828
NETFLOW_AGGREGATION_INTERVALS = [
29-
('1min', 60),
30-
('15min', 15 * 60),
31-
('1h', 3600),
32-
('4h', 4 * 3600),
33-
('24h', 24 * 3600),
29+
# label; interval; when to start first run (to make sure the runs are not aligned)
30+
('1min', 60, 0),
31+
('15min', 15 * 60, 15),
32+
('1h', 3600, 4*60 + 15),
33+
('4h', 4 * 3600, 29*60 + 15),
34+
('24h', 24 * 3600, 1*3600 + 29*60 + 15),
3435
]
3536
TOP_N_MAX = 10
3637

@@ -71,7 +72,7 @@ def jobs(self):
7172
accounts_infos[entity_info["account_id"]].append(entity_info)
7273

7374
for account_id, entities_infos in accounts_infos.items():
74-
for interval_label, interval in NETFLOW_AGGREGATION_INTERVALS:
75+
for interval_label, interval, first_run_ts in NETFLOW_AGGREGATION_INTERVALS:
7576
job_id = f'aggr/{interval_label}/{account_id}'
7677
job_params = {
7778
"job_id": job_id,
@@ -81,7 +82,8 @@ def jobs(self):
8182
"backend_url": self.backend_url,
8283
"bot_token": self.bot_token,
8384
}
84-
yield job_id, [interval], NetFlowBot.perform_account_aggr_job, job_params
85+
start_ts = int(time.time()) + first_run_ts - interval # start_ts must be in the past
86+
yield job_id, [interval], NetFlowBot.perform_account_aggr_job, job_params, start_ts
8587

8688

8789
@staticmethod

0 commit comments

Comments
 (0)