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

Catch second mastodon post failure #73

Merged
merged 3 commits into from
Sep 24, 2023
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
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ jobs:

- name: Build and Test
run: |
set -e
# pip install from requirements.txt
python -m pip install -r pip_requirements.txt
python -m pip install . --upgrade
coverage run --source=src setup.py test
coverage run --source=iembot setup.py test
coverage xml

- name: Code coverage
Expand Down
11 changes: 7 additions & 4 deletions src/iembot/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,21 +139,24 @@
# Submitted too quickly
log.err(exp)
# Since this called from a thread, sleeping should not jam us up
time.sleep(10)
time.sleep(kwargs.get("sleep", 10))

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

View check run for this annotation

Codecov / codecov/patch

src/iembot/util.py#L142

Added line #L142 was not covered by tests
res = api.status_post(**params)
except mastodon.errors.MastodonError as exp:
# Something else bad happened when submitting this to the Mastodon server
log.err(exp)
params.pop("media_ids", None) # Try again without media
# Since this called from a thread, sleeping should not jam us up
time.sleep(10)
res = api.status_post(**params)
time.sleep(kwargs.get("sleep", 10))
try:
res = api.status_post(**params)
except mastodon.errors.MastodonError as exp2:
log.err(exp2)
except Exception as exp:
# Something beyond Mastodon went wrong
log.err(exp)
params.pop("media_ids", None) # Try again without media
# Since this called from a thread, sleeping should not jam us up
time.sleep(10)
time.sleep(kwargs.get("sleep", 10))

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

View check run for this annotation

Codecov / codecov/patch

src/iembot/util.py#L159

Added line #L159 was not covered by tests
res = api.status_post(**params)
return res

Expand Down
13 changes: 13 additions & 0 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ def test_load_mastodon_from_db(dbcursor):
assert isinstance(bot.md_users, dict)


def test_util_toot():
"""Test the method."""
bot = JabberClient(None, None, xml_log_path="/tmp")
bot.md_users = {
"123": {
"screen_name": "iembot",
"access_token": "123",
"api_base_url": "https://localhost",
}
}
botutil.toot(bot, "123", "test", sleep=0)


def test_load_chatlog():
"""Test our pickling fun."""
bot = JabberClient(None, None, xml_log_path="/tmp")
Expand Down