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

Misskeyのクレデンシャル取得時にリトライ処理を入れる #3448

Merged
merged 5 commits into from
Nov 30, 2023
Merged
Changes from all commits
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
38 changes: 24 additions & 14 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from flask import Flask, jsonify, request
from markupsafe import escape
from misskey import Misskey
from requests.exceptions import ReadTimeout
from slackeventsapi import SlackEventAdapter

import slackbot_settings as conf
Expand Down Expand Up @@ -221,20 +222,29 @@ async def misskey_runner():
host = note["user"].get("host")
mentions = note.get("mentions")
if (
(host is None or host == conf.MISSKEY_DOMAIN)
and mentions
and misskey_client.i()["id"] in mentions
):
client = MisskeyClient(misskey_client, note)
try:
analyze.analyze_message(
note["text"]
.replace("\xa0", " ")
.split(" ", 1)[1]
)(client)
except Exception as e:
logger.exception(e)
client.post("エラーが発生したっぽ......")
host is None or host == conf.MISSKEY_DOMAIN
) and mentions:
cred = None

for i in range(10):
try:
cred = misskey_client.i()
break
except ReadTimeout as e:
logger.exception(e)
time.sleep(1)

if cred is not None and cred["id"] in mentions:
client = MisskeyClient(misskey_client, note)
try:
analyze.analyze_message(
note["text"]
.replace("\xa0", " ")
.split(" ", 1)[1]
)(client)
except Exception as e:
logger.exception(e)
client.post("エラーが発生したっぽ......")
except websockets.ConnectionClosedError:
time.sleep(1)

Expand Down