feat(bot): ✨ Move background tasks to separate image.
This commit is contained in:
+9
-3
@@ -1,4 +1,4 @@
|
||||
FROM python:3.12
|
||||
FROM python:3.12 AS base
|
||||
|
||||
WORKDIR /app
|
||||
COPY . .
|
||||
@@ -6,6 +6,12 @@ COPY . .
|
||||
RUN pip install uv
|
||||
RUN uv sync --no-dev
|
||||
|
||||
ENTRYPOINT [ "uv" ]
|
||||
|
||||
CMD [ "run", "--no-dev", "python3", "-u", "run.py" ]
|
||||
FROM base AS shard
|
||||
|
||||
ENTRYPOINT [ "uv", "run", "--no-dev", "bot.py" ]
|
||||
|
||||
|
||||
FROM base AS tasks
|
||||
|
||||
ENTRYPOINT [ "uv", "run", "--no-dev", "tasks.py" ]
|
||||
|
||||
+2
-2
@@ -17,7 +17,7 @@ spec:
|
||||
spec:
|
||||
containers:
|
||||
- name: bot
|
||||
image: git.nyeki.dev/payphone/payphone:latest
|
||||
image: git.nyeki.dev/payphone/payphone-shard:latest
|
||||
imagePullPolicy: "Always"
|
||||
envFrom:
|
||||
- configMapRef:
|
||||
@@ -41,7 +41,7 @@ spec:
|
||||
cpu: "250m"
|
||||
memory: "256Mi"
|
||||
imagePullSecrets:
|
||||
- name: regcred
|
||||
- name: regcred
|
||||
volumeClaimTemplates:
|
||||
- metadata:
|
||||
name: bot-storage
|
||||
|
||||
+1
-1
@@ -64,4 +64,4 @@ spec:
|
||||
storageClassName: "standard" # Update based on your storage class
|
||||
resources:
|
||||
requests:
|
||||
storage: 5Gi # Size for each pod's storage
|
||||
storage: 20Gi # Size for each pod's storage
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
apiVersion: batch/v1
|
||||
kind: CronJob
|
||||
metadata:
|
||||
name: tasks
|
||||
spec:
|
||||
schedule: "* * * * *"
|
||||
jobTemplate:
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: tasks
|
||||
image: git.nyeki.dev/payphone/payphone-tasks:latest
|
||||
command: ["uv", "run", "--no-dev", "tasks.py", "flush"]
|
||||
restartPolicy: OnFailure
|
||||
imagePullSecrets:
|
||||
- name: regcred
|
||||
@@ -238,11 +238,6 @@ class Calls(base.Cog):
|
||||
f"**TIP**: {secrets.choice(constants.TIPS).replace("{prefix}", ctx.clean_prefix)}\n"
|
||||
f"☎️ {secrets.choice(constants.MSGS_PHONE_CALLING)}\n"
|
||||
)
|
||||
+ (
|
||||
"⚠️ The phone will be hung up soon due to a scheduled restart.\n"
|
||||
if self.bot.scheduled_shutdown.value
|
||||
else ""
|
||||
)
|
||||
+ msg_phone_answered
|
||||
)
|
||||
|
||||
@@ -254,11 +249,6 @@ class Calls(base.Cog):
|
||||
f"**TIP**: {secrets.choice(constants.TIPS).replace("{prefix}", ctx.clean_prefix)}\n"
|
||||
f"☎️ {secrets.choice(constants.MSGS_PHONE_CALLING)}\n"
|
||||
)
|
||||
+ (
|
||||
"⚠️ The phone will be hung up soon due to a scheduled restart.\n"
|
||||
if self.bot.scheduled_shutdown.value
|
||||
else ""
|
||||
)
|
||||
)
|
||||
|
||||
@commands.command(aliases=["s"])
|
||||
@@ -436,11 +426,6 @@ class Calls(base.Cog):
|
||||
f"**TIP**: {secrets.choice(constants.TIPS).replace("{prefix}", ctx.clean_prefix)}\n"
|
||||
f"☎️ You skipped the call.\n"
|
||||
)
|
||||
+ (
|
||||
"⚠️ The phone will be hung up soon due to a scheduled restart.\n"
|
||||
if self.bot.scheduled_shutdown.value
|
||||
else ""
|
||||
)
|
||||
+ (
|
||||
msg_phone_answered
|
||||
if msg_phone_answered
|
||||
@@ -460,11 +445,6 @@ class Calls(base.Cog):
|
||||
f"☎️ You skipped the call.\n"
|
||||
f"☎️ {secrets.choice(constants.MSGS_PHONE_CALLING)}\n"
|
||||
)
|
||||
+ (
|
||||
"⚠️ The phone will be hung up soon due to a scheduled restart.\n"
|
||||
if self.bot.scheduled_shutdown.value
|
||||
else ""
|
||||
)
|
||||
)
|
||||
|
||||
@commands.command(aliases=["hang", "h"], extras={"help_name": "Hang Up"})
|
||||
|
||||
@@ -242,8 +242,6 @@ class Mods(base.Cog):
|
||||
- `[<reason>]`: The reason of the shutdown.
|
||||
"""
|
||||
|
||||
self.bot.scheduled_shutdown.value = True
|
||||
|
||||
if seconds > 0:
|
||||
oncall_channel_ids = list(
|
||||
await self.bot.redis.smembers(constants.CHANNELS_ONCALL_SET)
|
||||
@@ -321,9 +319,7 @@ class Mods(base.Cog):
|
||||
|
||||
await flush_messages.flush()
|
||||
|
||||
await ctx.send("⚡ Messages were flushed, payphone will shut down.")
|
||||
|
||||
self.bot.shutdown.value = True
|
||||
await ctx.send("⚡ Messages were flushed, payphone is ready to shut down.")
|
||||
|
||||
@commands.command()
|
||||
@commands.is_owner()
|
||||
|
||||
@@ -35,6 +35,6 @@ TORTOISE_ORM = {
|
||||
},
|
||||
}
|
||||
|
||||
SUGGESTIONS_CHANNEL_ID = int(os.getenv("SUGGESTIONS_CHANNEL_ID"))
|
||||
SUGGESTIONS_CHANNEL_ID = int(os.getenv("SUGGESTIONS_CHANNEL_ID", "0"))
|
||||
|
||||
SERVER_INVITE = os.getenv("SERVER_INVITE")
|
||||
|
||||
@@ -7,6 +7,7 @@ requires-python = ">=3.12"
|
||||
dependencies = [
|
||||
"aerich==0.7.1",
|
||||
"aiohttp>=3.10.10",
|
||||
"click>=8.1.7",
|
||||
"colorthief>=0.2.1",
|
||||
"httpx>=0.27.2",
|
||||
"orjson>=3.10.7",
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import asyncio
|
||||
|
||||
import functools
|
||||
|
||||
import click
|
||||
|
||||
from procs import flush_messages
|
||||
|
||||
from payphone.db import setup
|
||||
from payphone.core import logging
|
||||
|
||||
|
||||
logging.setup("Tasks")
|
||||
|
||||
|
||||
def coroutine(f):
|
||||
@functools.wraps(f)
|
||||
def wrapper(*args, **kwargs):
|
||||
return asyncio.run(f(*args, **kwargs))
|
||||
|
||||
return wrapper
|
||||
|
||||
|
||||
@click.group()
|
||||
@coroutine
|
||||
async def main():
|
||||
await setup.init()
|
||||
|
||||
|
||||
@main.command()
|
||||
@coroutine
|
||||
async def flush():
|
||||
await flush_messages.flush()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -392,6 +392,7 @@ source = { virtual = "." }
|
||||
dependencies = [
|
||||
{ name = "aerich" },
|
||||
{ name = "aiohttp" },
|
||||
{ name = "click" },
|
||||
{ name = "colorthief" },
|
||||
{ name = "httpx" },
|
||||
{ name = "orjson" },
|
||||
@@ -406,6 +407,7 @@ dependencies = [
|
||||
requires-dist = [
|
||||
{ name = "aerich", specifier = "==0.7.1" },
|
||||
{ name = "aiohttp", specifier = ">=3.10.10" },
|
||||
{ name = "click", specifier = ">=8.1.7" },
|
||||
{ name = "colorthief", specifier = ">=0.2.1" },
|
||||
{ name = "httpx", specifier = ">=0.27.2" },
|
||||
{ name = "orjson", specifier = ">=3.10.7" },
|
||||
|
||||
Reference in New Issue
Block a user