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

Robustness, hopefully #92

Merged
merged 2 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ ci:
autoupdate_schedule: quarterly
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.7.2"
rev: "v0.7.3"
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format

- repo: https://github.com/tox-dev/pyproject-fmt
rev: '2.4.3'
rev: 'v2.5.0'
hooks:
- id: pyproject-fmt
29 changes: 21 additions & 8 deletions src/iembot/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,16 @@
log.err(exp)

if at_handle not in bot.at_clients:
bot.at_clients[at_handle] = atproto.Client()
bot.at_clients[at_handle].login(
# This is racey, so we need to not add the client until we are
# sure it is logged in
client = atproto.Client()
client.login(

Check warning on line 67 in src/iembot/util.py

View check run for this annotation

Codecov / codecov/patch

src/iembot/util.py#L66-L67

Added lines #L66 - L67 were not covered by tests
at_handle,
bot.tw_users[user_id]["at_app_pass"],
)
# Again, racey, so we need to check again
if at_handle not in bot.at_clients:
bot.at_clients[at_handle] = client

Check warning on line 73 in src/iembot/util.py

View check run for this annotation

Codecov / codecov/patch

src/iembot/util.py#L72-L73

Added lines #L72 - L73 were not covered by tests

if msg.find("http") > -1:
parts = msg.split("http")
Expand All @@ -75,12 +80,20 @@
.link("link", f"http{parts[1]}")
)

if img:
res = bot.at_clients[at_handle].send_image(
msg, image=img, image_alt="IEMBot Image TBD"
)
else:
res = bot.at_clients[at_handle].send_post(msg)
for attempt in range(1, 4):
try:
if img:
res = bot.at_clients[at_handle].send_image(

Check warning on line 86 in src/iembot/util.py

View check run for this annotation

Codecov / codecov/patch

src/iembot/util.py#L83-L86

Added lines #L83 - L86 were not covered by tests
msg, image=img, image_alt="IEMBot Image TBD"
)
else:
res = bot.at_clients[at_handle].send_post(msg)
break
except Exception as exp:
log.err(exp)
time.sleep(attempt * 5)
if attempt == 3:
raise exp

Check warning on line 96 in src/iembot/util.py

View check run for this annotation

Codecov / codecov/patch

src/iembot/util.py#L90-L96

Added lines #L90 - L96 were not covered by tests
# for now
log.msg(repr(res))
return res
Expand Down