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

Replace sync_to_async with database_sync_to_async #356

Merged
merged 4 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/355.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed "Server has gone away" error in Slack Socket Mode.
8 changes: 4 additions & 4 deletions nautobot_chatops/sockets/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import json
import shlex

from asgiref.sync import sync_to_async
from channels.db import database_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 @@ -72,7 +72,7 @@ async def process_slash_command(client, req):
client.logger.error("%s", err)
return

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

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

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

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

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

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

if command not in registry:
SlackDispatcher(context).send_markdown(commands_help(prefix=SLASH_PREFIX))
Expand Down
4 changes: 2 additions & 2 deletions nautobot_chatops/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sys
from datetime import datetime, timezone

from asgiref.sync import sync_to_async
from channels.db import database_sync_to_async
from django.conf import settings
from django.db.models import Q
from django.http import HttpResponse, JsonResponse
Expand Down Expand Up @@ -113,7 +113,7 @@ def create_command_log(dispatcher, registry, command, subcommand, params=()):
)


@sync_to_async
@database_sync_to_async
def socket_check_and_enqueue_command(*args, **kwargs):
"""Calls check_and_enqueue_command() when in Socket mode."""
return check_and_enqueue_command(*args, **kwargs)
Expand Down
23 changes: 21 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ aiodns = "^1.0"
aiohttp = "^3.7.3"
asgiref = "^3.4.1"
certifi = { version = ">=2021.5.30", optional = true }
channels = "^4.2.0"
cloudvision = { version = "^1.1", optional = true }
cvprac = { version = "^1.0.6", optional = true }
defusedxml = { version = "^0.7.1", optional = true }
Expand Down
Loading