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

fix: add queue for Slack events #1892

Merged
merged 1 commit into from Mar 9, 2022

Conversation

martinohmann
Copy link
Contributor

@martinohmann martinohmann commented Mar 2, 2022

Description

The Slack Events API documentation states:

Your app should respond to the event request with an HTTP 2xx within three seconds. If it does not, we'll consider the event delivery attempt failed. After a failure, we'll retry three times, backing off exponentially.

[...]

Respond to events with a HTTP 200 OK as soon as you can. Avoid actually processing and reacting to events within the same process. Implement a queue to handle inbound events after they are received.

https://api.slack.com/apis/connections/events-api#the-events-api__responding-to-events

This PR adds an asyncio.Queue which incoming events are pushed into. The web_handler will return HTTP Status 200 to Slack immediately and the event is processed asynchronously in the background.

I'm fairly new to async python, so please let me know if there is a more idiomatic way to achieve this and I'll update the PR accordingly.

We're already using this fix in production and so far it works flawlessly.

Fixes #1890

Status

READY

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Existing test suite and manual tests against a real Slack workspace.

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation (if applicable)
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@codecov
Copy link

codecov bot commented Mar 2, 2022

Codecov Report

Merging #1892 (50f4440) into master (1bdafbd) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1892   +/-   ##
=======================================
  Coverage   99.37%   99.37%           
=======================================
  Files          83       83           
  Lines        5089     5102   +13     
=======================================
+ Hits         5057     5070   +13     
  Misses         32       32           
Impacted Files Coverage Δ
opsdroid/connector/slack/connector.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1bdafbd...50f4440. Read the comment docs.

Copy link
Member

@FabioRosado FabioRosado left a comment

Choose a reason for hiding this comment

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

Thank you for working on this fix! Glad you have it working in production!
I'll test the fix later today and will approve later, I've also re-run CI to see if the windows tests pass

"""Disconnect from Slack.

Cancels the event queue worker task and disconnects the
socket_mode_client if socket mode was enabled."""
Copy link
Member

Choose a reason for hiding this comment

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

Small nitpick, feel free to ignore

Suggested change
socket_mode_client if socket mode was enabled."""
socket_mode_client if socket mode was enabled.
"""

Copy link
Member

@FabioRosado FabioRosado left a comment

Choose a reason for hiding this comment

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

Apologies took me longer than I wished for! Going to approve and merge this MR thank you for fixing the issue 😄 👍

@FabioRosado FabioRosado merged commit 5bfe4c8 into opsdroid:master Mar 9, 2022
@martinohmann
Copy link
Contributor Author

@FabioRosado no worries, thanks for accepting the PR! :) Do you have any estimates when the next opsdroid release is planned? Thanks for your work!

@FabioRosado
Copy link
Member

No worries! We tend to release monthly but we may skip a release if no new things got in.

I'll try to get some work done and maybe see if we can release soonish 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Get multiple responses for one slack input command
2 participants