perf: low priority for backup processes
This commit is contained in:
parent
edf92d4450
commit
9d3be5160f
2 changed files with 17 additions and 10 deletions
|
|
@ -307,14 +307,23 @@ def unesc(s, esc_chars):
|
|||
s = s.replace(esc_str, c)
|
||||
return s
|
||||
|
||||
def execute_in_shell(cmd, verbose=0):
|
||||
def execute_in_shell(cmd, verbose=0, low_priority=False):
|
||||
# using Popen instead of os.system - as recommended by python docs
|
||||
import tempfile
|
||||
from subprocess import Popen
|
||||
|
||||
with tempfile.TemporaryFile() as stdout:
|
||||
with tempfile.TemporaryFile() as stderr:
|
||||
p = Popen(cmd, shell=True, stdout=stdout, stderr=stderr)
|
||||
kwargs = {
|
||||
"shell": True,
|
||||
"stdout": stdout,
|
||||
"stderr": stderr
|
||||
}
|
||||
|
||||
if low_priority:
|
||||
kwargs["preexec_fn"] = lambda: os.nice(10)
|
||||
|
||||
p = Popen(cmd, **kwargs)
|
||||
p.wait()
|
||||
|
||||
stdout.seek(0)
|
||||
|
|
|
|||
|
|
@ -315,8 +315,6 @@ class BackupGenerator:
|
|||
print(template.format(_type.title(), info["path"], info["size"]))
|
||||
|
||||
def backup_files(self):
|
||||
import subprocess
|
||||
|
||||
for folder in ("public", "private"):
|
||||
files_path = frappe.get_site_path(folder, "files")
|
||||
backup_path = (
|
||||
|
|
@ -327,12 +325,12 @@ class BackupGenerator:
|
|||
cmd_string = "tar cf - {1} | gzip > {0}"
|
||||
else:
|
||||
cmd_string = "tar -cf {0} {1}"
|
||||
output = subprocess.check_output(
|
||||
cmd_string.format(backup_path, files_path), shell=True
|
||||
)
|
||||
|
||||
if self.verbose and output:
|
||||
print(output.decode("utf8"))
|
||||
frappe.utils.execute_in_shell(
|
||||
cmd_string.format(backup_path, files_path),
|
||||
verbose=self.verbose,
|
||||
low_priority=True
|
||||
)
|
||||
|
||||
def copy_site_config(self):
|
||||
site_config_backup_path = self.backup_path_conf
|
||||
|
|
@ -436,7 +434,7 @@ class BackupGenerator:
|
|||
if self.verbose:
|
||||
print(command + "\n")
|
||||
|
||||
err, out = frappe.utils.execute_in_shell(command)
|
||||
err, out = frappe.utils.execute_in_shell(command, low_priority=True)
|
||||
|
||||
def send_email(self):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue