From 82df3ebddb6d654784def26f1b8f6bf0b8f035dc Mon Sep 17 00:00:00 2001 From: Jim Ladd Date: Fri, 19 Feb 2021 16:58:19 -0800 Subject: [PATCH] add option to create partitions that span a single minute * turned on by default currently for testing --- awx/main/utils/common.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/awx/main/utils/common.py b/awx/main/utils/common.py index 4dcd207dc6..a65dca2dd6 100644 --- a/awx/main/utils/common.py +++ b/awx/main/utils/common.py @@ -1026,21 +1026,33 @@ def deepmerge(a, b): return b -def create_partition(start=None, end=None, partition_label=None): +def create_partition(start=None, end=None, partition_label=None, minutely=True): """Creates new partition tables for events. - start defaults to beginning of current hour - end defaults to end of current hour - - partition_label defaults to YYYYMMDD_HH""" + - partition_label defaults to YYYYMMDD_HH + - minutely will create partitions that span _a single minute_ for testing purposes + """ + current_time = now() if not start: - start = now().replace(microsecond=0, second=0, minute=0) + if minutely: + start = current_time.replace(microsecond=0, second=0) + else: + start = current_time.replace(microsecond=0, second=0, minute=0) if not end: - end = start.replace(microsecond=0, second=0, minute=0) + timedelta(hours=1) + if minutely: + end = start.replace(microsecond=0, second=0) + timedelta(minutes=1) + else: + end = start.replace(microsecond=0, second=0, minute=0) + timedelta(hours=1) start_timestamp = str(start) end_timestamp = str(end) if not partition_label: - partition_label = start.strftime('%Y%m%d_%H') + if minutely: + partition_label = start.strftime('%Y%m%d_%H%M') + else: + partition_label = start.strftime('%Y%m%d_%H') with connection.cursor() as cursor: # Only partitioning main_jobevent on first pass