Skip to content

Commit 75a2804

Browse files
committed
Use timestamps instead of integers (/UNIX timestamps)
1 parent e64098d commit 75a2804

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

dbutils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,4 @@ def migration_step_6():
189189
);
190190
""")
191191
c.execute(f"SELECT create_hypertable('{DB_PREFIX}flows2', 'ts', chunk_time_interval => INTERVAL '1 hour');")
192+
c.execute(f'CREATE TABLE {DB_PREFIX}bot_jobs2 (job_id TEXT NOT NULL PRIMARY KEY, last_used_ts TIMESTAMP NOT NULL);')

netflowbot.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ def path_part_encode(s):
5555

5656
def _get_last_used_ts(job_id):
5757
with get_db_cursor() as c:
58-
c.execute(f'SELECT j.last_used_ts FROM {DB_PREFIX}bot_jobs j WHERE j.job_id = %s;', (job_id,))
58+
c.execute(f'SELECT j.last_used_ts FROM {DB_PREFIX}bot_jobs2 j WHERE j.job_id = %s;', (job_id,))
5959
rec = c.fetchone()
6060
if rec is None:
6161
return None
6262
last_used_ts, = rec
63-
return int(last_used_ts)
63+
return last_used_ts
6464

6565
def _get_current_max_ts():
6666
with get_db_cursor() as c:
@@ -73,7 +73,7 @@ def _get_current_max_ts():
7373

7474
def _save_current_max_ts(job_id, max_ts):
7575
with get_db_cursor() as c:
76-
c.execute(f"INSERT INTO {DB_PREFIX}bot_jobs (job_id, last_used_ts) VALUES (%s, %s) ON CONFLICT (job_id) DO UPDATE SET last_used_ts = %s;", (job_id, max_ts, max_ts))
76+
c.execute(f"INSERT INTO {DB_PREFIX}bot_jobs2 (job_id, last_used_ts) VALUES (%s, %s) ON CONFLICT (job_id) DO UPDATE SET last_used_ts = %s;", (job_id, max_ts, max_ts))
7777

7878

7979
def job_maint_remove_old_data(*args, **kwargs):
@@ -168,10 +168,10 @@ def jobs(self):
168168

169169
@staticmethod
170170
def perform_account_aggr_job(*args, **job_params):
171-
# \d netflow_flows
171+
# \d netflow_flows2
172172
# Column | Type | Description
173173
# ---------------+---------------+------------
174-
# ts | numeric(16,6) | UNIX timestamp
174+
# ts | timestamp | time when flow was received by netflowcollector
175175
# client_ip | inet | entity IP address
176176
# in_bytes | integer | number of bytes associated with an IP Flow
177177
# protocol | smallint | IP protocol (see lookup.py -> PROTOCOLS)

0 commit comments

Comments
 (0)