Skip to content
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

refactor some callback receiver code #8236

Merged

Conversation

ryanpetrello
Copy link
Contributor

@ryanpetrello ryanpetrello commented Sep 25, 2020

the bigint migration (#6032) removed the foreign key constraints for:

  • host_id
  • job_id (and projectupdate_id, etc...)

I'd like to say this was intentional, but I actually think is was an unexpected
side effect of my work that happened to work out in our favor.

because of this, we don't really need to check explicitly for a host_id
IntegrityError anymore (because it won't occur)

additionally, while it's possible to insert an event with a mismatched
job_id now (for example, you can totally start a long-running job, and
delete the job record in the background using the ORM or psql), doing
so results in DoesNotExist errors in the code that handles the
playbook_on_stats events

cc @gamuniz

@softwarefactory-project-zuul
Copy link
Contributor

Build failed.

for e in events:
try:
if (
isinstance(exc, IntegrityError) and
getattr(e, 'host_id', '')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This foreign key constraint just doesn't exist anymore at all (go ahead and go check 😄 \d main_jobevent).

def _send_notifications():
handle_success_and_failure_notifications.apply_async([self.job.id])
connection.on_commit(_send_notifications)
try:
Copy link
Contributor Author

@ryanpetrello ryanpetrello Sep 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The job_id constraint doesn't exist either, so it's totally possible to insert a playbook_on_stats for a job that no longer exists. When that's the case, this code will blow up. This is probably a little difficult to hit in practice, because the API actually prevents you from deleting a job that's still processing events.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"the API actually prevents you from deleting a job that's still processing events, until 2 minutes after the job is finished" But yeah, it's still hard to hit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, it can happen. Kind of hard to get here, but better to have this work properly 👍

@@ -497,7 +503,11 @@ def _hostnames(self):

def _update_host_summary_from_stats(self, hostnames):
with ignore_inventory_computed_fields():
if not self.job or not self.job.inventory:
try:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code will also blow up in the scenario described above.

@ryanpetrello
Copy link
Contributor Author

recheck

@softwarefactory-project-zuul
Copy link
Contributor

Build failed.

the bigint migration removed the foreign key constraints for:

- host_id
- job_id (and projectupdate_id, etc...)

because of this, we don't really need to check explicitly for a host_id
IntegrityError anymore (because it won't occur)

additionally, while it's possible to insert an event with a mismatched
job_id now (for example, you can totally start a long-running job, and
delete the job record in the background using the ORM or psql), doing
so results in DoesNotExist errors in the code that handles the
playbook_on_stats events
@softwarefactory-project-zuul
Copy link
Contributor

Build succeeded.

@softwarefactory-project-zuul
Copy link
Contributor

Build succeeded (gate pipeline).

@softwarefactory-project-zuul softwarefactory-project-zuul bot merged commit 36d4f25 into ansible:devel Sep 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants