From 11890f0eeea11fd48ed2e5144d706becde6df43c Mon Sep 17 00:00:00 2001 From: Jeff Bradberry Date: Wed, 13 Apr 2022 11:06:35 -0400 Subject: [PATCH] Fix the job event partition alignment it really should be always aligned to the hour, so that real job events don't slip through the cracks. --- awx/main/utils/common.py | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/awx/main/utils/common.py b/awx/main/utils/common.py index 73bbb48f6c..19394247b3 100644 --- a/awx/main/utils/common.py +++ b/awx/main/utils/common.py @@ -1113,33 +1113,18 @@ def deepmerge(a, b): return b -def create_partition(tblname, start=None, end=None, partition_label=None, minutely=False): - """Creates new partition table for events. - - start defaults to beginning of current hour - - end defaults to end of current hour - - partition_label defaults to YYYYMMDD_HH +def create_partition(tblname, start=None): + """Creates new partition table for events. By default it covers the current hour.""" + if start is None: + start = now() + + start = start.replace(microsecond=0, second=0, minute=0) + end = start + timedelta(hours=1) - - minutely will create partitions that span _a single minute_ for testing purposes - """ - current_time = now() - if not start: - if minutely: - start = current_time.replace(microsecond=0, second=0) - else: - start = current_time.replace(microsecond=0, second=0, minute=0) - if not end: - 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: - if minutely: - partition_label = start.strftime('%Y%m%d_%H%M') - else: - partition_label = start.strftime('%Y%m%d_%H') + partition_label = start.strftime('%Y%m%d_%H') try: with transaction.atomic():