Skip to content

Commit

Permalink
Resolve synchronous function running in the Async Slack Socket Mode (#…
Browse files Browse the repository at this point in the history
…350)

* Wrap get_commands_registry with sync_to_async

* Move Pull Request Template so that Github picks this up.

* Update changes/348.fixed

Co-authored-by: Gary Snider <[email protected]>

---------

Co-authored-by: Gary Snider <[email protected]>
  • Loading branch information
smk4664 and gsnider2195 authored Dec 18, 2024
1 parent ea2b5c4 commit 3a83a6a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
File renamed without changes.
1 change: 1 addition & 0 deletions changes/348.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed failure when running slack socket mode.
7 changes: 4 additions & 3 deletions nautobot_chatops/sockets/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import json
import shlex

from asgiref.sync import sync_to_async
from django.conf import settings
from slack_sdk.socket_mode.aiohttp import SocketModeClient
from slack_sdk.socket_mode.request import SocketModeRequest
Expand Down Expand Up @@ -71,7 +72,7 @@ async def process_slash_command(client, req):
client.logger.error("%s", err)
return

registry = get_commands_registry()
registry = await sync_to_async(get_commands_registry)()

if command not in registry:
SlackDispatcher(context).send_markdown(commands_help(prefix=SLASH_PREFIX))
Expand Down Expand Up @@ -210,7 +211,7 @@ async def process_interactive(client, req):

client.logger.info(f"command: {command}, subcommand: {subcommand}, params: {params}")

registry = get_commands_registry()
registry = await sync_to_async(get_commands_registry)()

if command not in registry:
SlackDispatcher(context).send_markdown(commands_help(prefix=SLASH_PREFIX))
Expand Down Expand Up @@ -241,7 +242,7 @@ async def process_mention(client, req):
client.logger.error("%s", err)
return

registry = get_commands_registry()
registry = await sync_to_async(get_commands_registry)()

if command not in registry:
SlackDispatcher(context).send_markdown(commands_help(prefix=SLASH_PREFIX))
Expand Down

0 comments on commit 3a83a6a

Please sign in to comment.