-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add management command to precreate partitioned tables #14076
Add management command to precreate partitioned tables #14076
Conversation
def _create_partitioned_tables(self, count): | ||
start = now() | ||
while count > 0: | ||
for table in ("main_inventoryupdateevent", "main_jobevent", "main_projectupdateevent", "main_systemjobevent"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to make 1 request that we don't hard-code these table names. Import this method instead, you may find it necessary to move into utils:
awx/awx/main/management/commands/cleanup_jobs.py
Lines 22 to 23 in f1196fc
def unified_job_class_to_event_table_name(job_class): | |
return f'main_{job_class().event_class.__name__.lower()}' |
With that method, you don't need to provide a table name for the loop, but you do need to provide the models. Those would be Job, AdHocCommand, ProjectUpdate, InventoryUpdate, SystemJob.
I listed 5 and you listed 4, I think you're missing the ad hoc commands as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I refactored based on your feedback @AlanCoding. Let me know if you had something different in mind here.
while count > 0: | ||
for table in tables: | ||
create_partition(table, start) | ||
print(f'Creating partitions for {table} {start}') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm just slightly confused about this message coming after the create_partition call. Maybe it should say "Created" instead of "creating"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I agree, that message was mostly for me during writing/debug to make sure I had the correct tables/timestamps
Useful for automating a pg_dump as it holds exclusive locks on main_jobevent etc during a pg_dump example of automation: - name: precreate partitioned tables shell: awx-manage precreate_partitions become_user: awx become: true register: partitions
Imported the function to cleanup_jobs.py and precreate_partitions.py Removed hardcoded table names in favor of looping through the models
f8a5abd
to
202a328
Compare
SUMMARY
Useful for automating a pg_dump as it holds exclusive locks on main_jobevent etc during a pg_dump
example of automation:
ISSUE TYPE
COMPONENT NAME
AWX VERSION
ADDITIONAL INFORMATION