hberp/hb_server/apps/develop/tasks.py

25 lines
668 B
Python

from __future__ import absolute_import, unicode_literals
from rest_framework.response import Response
from celery import shared_task
import os
import subprocess
@shared_task
def backup_database():
"""
备份数据库
"""
completed = subprocess.run('sudo pg_dump "user=postgres password=zcDsj2021 dbname=hberp" > /home/lighthouse/hberp_backup.sql',
shell=True, capture_output=True, text=True)
return completed
@shared_task
def reload_server():
os.chdir('/home/lighthouse/hberp')
completed = subprocess.run('sudo git pull && sudo service supervisor reload', shell=True, capture_output=True, text=True)
return completed