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

Don't trigger a sync twice on creation/deletion for GitHub #6614

Merged
merged 10 commits into from Feb 18, 2020

Conversation

stsewd
Copy link
Member

@stsewd stsewd commented Jan 29, 2020

We are listening for creation/deletion on push events for old webhooks.

Another solution is to don't listen to push events for creation/deletion and force users to update those events in their old webhooks. Listening for creations/deletion on push events in old webhoooks was introduced in #6465

@stsewd stsewd requested a review from Feb 12, 2020
Copy link
Member

@ericholscher ericholscher left a comment

Looks like a good approach. 👍

readthedocs/api/v2/views/integrations.py Outdated Show resolved Hide resolved
# GitHub will send push and create/delete events on a creation/deletion.
# If we receive a push event we need to check if the webhook doesn't
# already have the create/delete events. So we don't trigger the sync twice.
# We listen to push events for creation/deletion for old webhooks only.
Copy link
Member

@ericholscher ericholscher Feb 12, 2020

Choose a reason for hiding this comment

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

Good comment 👍

Copy link
Member

@humitos humitos Feb 13, 2020

Choose a reason for hiding this comment

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

I don't follow this code 😢

We are already handling GITHUB_PUSH in the previous if with deleted or created (line 382), why don't we just remove the GITHUB_PUSH from this elif (line 389) instead? That seems to do the same without extra code.

Like this on line 389:

elif event in (GITHUB_CREATE, GITHUB_DELETE):
    return self.sync_versions(self.project)

That way, we are only syncing versions on CREATE and DELETE, but not on regular PUSH.

Copy link
Member

@humitos humitos Feb 13, 2020

Choose a reason for hiding this comment

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

I think what we want is:

  • GITHUB_PUSH and (created or deleted) -> sync versions
  • GITHUB_CREATE or GITHUB_DELETE -> sync versions
  • all the other possibilities -> do not sync versions

If this is correct, I do see this logic easier to understand than our current implementation.

Copy link
Member Author

@stsewd stsewd Feb 17, 2020

Choose a reason for hiding this comment

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

We are already handling GITHUB_PUSH in the previous if with deleted or created

We are triggering a build in that case, and we check for not (deleted or created)

why don't we just remove the GITHUB_PUSH from this elif (line 389) instead?

We want to listen to PUSH events for sync, but only trigger a sync if the webhook isn't subscribed to creation/deletion events.

Copy link
Member Author

@stsewd stsewd Feb 17, 2020

Choose a reason for hiding this comment

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

GitHub will send two events when a branch/tag is created/deleted (if the webhook is listening to creation/deletion events), that's why we need to discard the push event in that case.

GITHUB_PUSH and (created or deleted) -> sync versions

That will still need to check if the webhook isn't subscribed to creation/deletion. Otherwise it'll trigger two syncs.

GITHUB_CREATE or GITHUB_DELETE -> sync versions

This will trigger a second sync for users that have webhooks listening to creation/deletion events.

Copy link
Member

@humitos humitos left a comment

I'd like to discuss a little more this implementation to be sure that I'm understanding what we are doing here before merging. Also, I'm suggesting another way to implement this that I think it's simpler and easier to read.

readthedocs/api/v2/views/integrations.py Outdated Show resolved Hide resolved
readthedocs/api/v2/views/integrations.py Outdated Show resolved Hide resolved
# GitHub will send push and create/delete events on a creation/deletion.
# If we receive a push event we need to check if the webhook doesn't
# already have the create/delete events. So we don't trigger the sync twice.
# We listen to push events for creation/deletion for old webhooks only.
Copy link
Member

@humitos humitos Feb 13, 2020

Choose a reason for hiding this comment

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

I don't follow this code 😢

We are already handling GITHUB_PUSH in the previous if with deleted or created (line 382), why don't we just remove the GITHUB_PUSH from this elif (line 389) instead? That seems to do the same without extra code.

Like this on line 389:

elif event in (GITHUB_CREATE, GITHUB_DELETE):
    return self.sync_versions(self.project)

That way, we are only syncing versions on CREATE and DELETE, but not on regular PUSH.

readthedocs/rtd_tests/tests/test_api.py Show resolved Hide resolved
# GitHub will send push and create/delete events on a creation/deletion.
# If we receive a push event we need to check if the webhook doesn't
# already have the create/delete events. So we don't trigger the sync twice.
# We listen to push events for creation/deletion for old webhooks only.
Copy link
Member

@humitos humitos Feb 13, 2020

Choose a reason for hiding this comment

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

I think what we want is:

  • GITHUB_PUSH and (created or deleted) -> sync versions
  • GITHUB_CREATE or GITHUB_DELETE -> sync versions
  • all the other possibilities -> do not sync versions

If this is correct, I do see this logic easier to understand than our current implementation.

@ericholscher
Copy link
Member

@ericholscher ericholscher commented Feb 17, 2020

@stsewd Thoughts on Manuel's comments? Need to address those before merging.

@stsewd
Copy link
Member Author

@stsewd stsewd commented Feb 17, 2020

@ericholscher I added the missing test and put the default value on the model. I also replied to #6614 (comment)

@ericholscher
Copy link
Member

@ericholscher ericholscher commented Feb 17, 2020

@ericholscher I added the missing test and put the default value on the model. I also replied to #6614 (comment)

Weird, it doesn't show it later in the PR thread, really confusing.

@ericholscher
Copy link
Member

@ericholscher ericholscher commented Feb 18, 2020

Alright, I'm gonna go ahead and merge this, since I think it makes sense. We will see if it blows up in prod :)

@ericholscher ericholscher merged commit 0692076 into readthedocs:master Feb 18, 2020
2 checks passed
@stsewd stsewd deleted the dont-trigger-two-syncs branch Feb 18, 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.

None yet

3 participants