Improved code quality with more idiomatic Python patterns and safer initialization.
CI / Formatting (push) Successful in 5s
CI / Linting (push) Successful in 4s
CI / Tests (push) Successful in 21s
CI / Type Checking (push) Failing after 10s
CI / Spelling (push) Successful in 5s

This commit is contained in:
2026-03-22 14:41:38 -04:00
parent 371f7d2ca3
commit 2cf00fde4f
13 changed files with 148 additions and 79 deletions
+14
View File
@@ -1 +1,15 @@
# Copyright 2026 Logan Fick
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Background tasks for Crabstero."""
+27 -35
View File
@@ -59,40 +59,32 @@ async def ingest_channel(
:param channel: The channel to ingest.
:param db: The database instance.
"""
try:
if not channel.permissions_for(channel.guild.me).read_message_history:
logger.warning(
"[%s] Unable to ingest channel history"
" due to lacking permissions. Ignoring.",
channel.id,
)
return
if await db.is_channel_ingested(channel.id):
return
await db.mark_channel_ingested(channel.id)
logger.info("[%s] Starting ingestion of textable channel history.", channel.id)
with metrics.CHANNEL_INGESTION_DURATION.time():
count = 0
async for message in channel.history(limit=MAXIMUM_MESSAGES_PER_CHANNEL):
count += 1
await ingest_message(db, message)
metrics.CHANNEL_INGESTION_MESSAGES.observe(count)
logger.info(
"[%s] Ingestion of channel history complete. %d messages ingested.",
channel.id,
count,
)
metrics.CHANNELS_INGESTED.inc()
except Exception:
metrics.CHANNEL_INGESTION_ERRORS.inc()
logger.exception(
"[%s] An error occurred while ingesting textable channel history!",
if not channel.permissions_for(channel.guild.me).read_message_history:
logger.warning(
"[%s] Unable to ingest channel history"
" due to lacking permissions. Ignoring.",
channel.id,
)
return
if await db.is_channel_ingested(channel.id):
return
await db.mark_channel_ingested(channel.id)
logger.info("[%s] Starting ingestion of textable channel history.", channel.id)
with metrics.CHANNEL_INGESTION_DURATION.time():
count = 0
async for message in channel.history(limit=MAXIMUM_MESSAGES_PER_CHANNEL):
count += 1
await ingest_message(db, message)
metrics.CHANNEL_INGESTION_MESSAGES.observe(count)
logger.info(
"[%s] Ingestion of channel history complete. %d messages ingested.",
channel.id,
count,
)
metrics.CHANNELS_INGESTED.inc()