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

Duplicate messages #4

Open
rcoup opened this issue Oct 25, 2017 · 4 comments
Open

Duplicate messages #4

rcoup opened this issue Oct 25, 2017 · 4 comments

Comments

@rcoup
Copy link
Contributor

rcoup commented Oct 25, 2017

Hi,

When we do uploads we end up getting duplicate messages posted to Slack (eg. "Uploaded mypackage==3.0.dev1234 to https://devpi.example.com"). My initial guess is that maybe the source tgz and the wheel components are both treated as uploads independently, so we get the message twice?

Could devpi_slack suppress dupe messages? eg. compare the latest message to the previous one sent and skip if they match. Wouldn't be perfect in edge cases but is a pretty simple 99% solution.

@max-arnold
Copy link
Contributor

Hi Robert.

This is just an event handler and I do not know where to store the state of any previous calls. The hook itself is defined here https://github.com/devpi/devpi/blob/master/server/devpi_server/hookspecs.py#L103 and is called from view here https: //github.com/devpi/devpi/blob/master/server/devpi_server/views.py#L790

If you are familiar with devpi internals, try to add some logging around this call to see why you have duplicate events. In my setup there is only one message per upload, so I can't reproduce your issue.

@rcoup
Copy link
Contributor Author

rcoup commented Oct 25, 2017

Hmm, so you're uploading wheels + tgzs for the same packages but not seeing it? I'll do some more investigation in devpi-server and try and figure out whats going on. I'm running 4.3.0.

FWIW, the sort of workaround I was vaguely thinking of. Will drum up a PR if I can't find anything wrong in devpi.

last_message = None

...
def devpiserver_on_upload_sync(log, application_url, stage, project, version):
    global last_message
    ...
    message = "Uploaded {}=={} to {}".format(
                        project,
                        version,
                        application_url
                    )
    if message == last_message:
       log.debug("skipping duplicate Slack notification: %s", message)
       return

    session = new_requests_session(agent=("devpi-slack", __version__))
    try:
        r = session.post(
            slack_hook,
            data={
                'payload': json.dumps({
                    "text": message,
                    "icon_url": slack_icon,
                    "username": slack_user,
                })
            })
    except session.Errors:
        raise RuntimeError("%s: failed to send Slack notification %s",
                           project, slack_hook)

    if 200 <= r.status_code < 300:
        log.info("successfully sent Slack notification: %s", slack_hook)
        last_message = message
    else:
    ...

@rcoup
Copy link
Contributor Author

rcoup commented Oct 27, 2017

So, we don't see duplicates for packages with just a tgz, and we do for whl+tgz packages. From looking into devpi, the hook is triggered from each upload, and the client uploads files individually/separately, so that would explain it.

@max-arnold
Copy link
Contributor

devpi/devpi#470

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

No branches or pull requests

2 participants