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.
This commit is contained in:
Jeff Bradberry 2022-04-13 11:06:35 -04:00
parent a3e29317c5
commit 11890f0eee

View File

@ -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():