Bot container restart from admin-panel
This commit is contained in:
21
lottery/bot/tasks.py
Normal file
21
lottery/bot/tasks.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from celery import shared_task
|
||||
import subprocess
|
||||
|
||||
@shared_task
|
||||
def restart_bot_container(container_name="bot"):
|
||||
try:
|
||||
result = subprocess.run(
|
||||
["docker", "restart", container_name],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
text=True,
|
||||
check=True
|
||||
)
|
||||
return f"Success: {result.stdout.strip()}"
|
||||
except subprocess.CalledProcessError as e:
|
||||
return f"Error restarting container: {e.stderr.strip()}"
|
||||
|
||||
|
||||
@shared_task
|
||||
def ping():
|
||||
return "pong"
|
||||
Reference in New Issue
Block a user