mirror of
https://github.com/tuna/tunasync.git
synced 2025-06-15 14:12:47 +00:00
link fail log
This commit is contained in:
parent
e278f7901f
commit
5f8e113364
@ -21,6 +21,7 @@ class LogLimitHook(JobHook):
|
|||||||
return
|
return
|
||||||
|
|
||||||
log_link = os.path.join(log_dir, "latest")
|
log_link = os.path.join(log_dir, "latest")
|
||||||
|
ctx['log_link'] = log_link
|
||||||
|
|
||||||
lfiles = [os.path.join(log_dir, lfile)
|
lfiles = [os.path.join(log_dir, lfile)
|
||||||
for lfile in os.listdir(log_dir)
|
for lfile in os.listdir(log_dir)
|
||||||
@ -42,7 +43,31 @@ class LogLimitHook(JobHook):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
# create a soft link
|
# create a soft link
|
||||||
if log_link != log_file:
|
self.create_link(log_link, log_file)
|
||||||
|
|
||||||
|
def after_job(self, status=None, ctx={}, *args, **kwargs):
|
||||||
|
log_file = ctx.get('log_file', None)
|
||||||
|
log_link = ctx.get('log_link', None)
|
||||||
|
if log_file == "/dev/null":
|
||||||
|
return
|
||||||
|
if status == "fail":
|
||||||
|
log_file_save = log_file + ".fail"
|
||||||
|
try:
|
||||||
|
sh.mv(log_file, log_file_save)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
self.create_lin(log_link, log_file_save)
|
||||||
|
|
||||||
|
def ensure_log_dir(self, log_dir):
|
||||||
|
if not os.path.exists(log_dir):
|
||||||
|
sh.mkdir("-p", log_dir)
|
||||||
|
|
||||||
|
def create_link(self, log_link, log_file):
|
||||||
|
if log_link == log_file:
|
||||||
|
return
|
||||||
|
if not (log_link and log_file):
|
||||||
|
return
|
||||||
|
|
||||||
if os.path.lexists(log_link):
|
if os.path.lexists(log_link):
|
||||||
try:
|
try:
|
||||||
sh.rm(log_link)
|
sh.rm(log_link)
|
||||||
@ -53,19 +78,5 @@ class LogLimitHook(JobHook):
|
|||||||
except:
|
except:
|
||||||
return
|
return
|
||||||
|
|
||||||
def after_job(self, status=None, ctx={}, *args, **kwargs):
|
|
||||||
log_file = ctx.get('log_file', None)
|
|
||||||
if log_file == "/dev/null":
|
|
||||||
return
|
|
||||||
if status == "fail":
|
|
||||||
log_file_save = log_file + ".fail"
|
|
||||||
try:
|
|
||||||
sh.mv(log_file, log_file_save)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def ensure_log_dir(self, log_dir):
|
|
||||||
if not os.path.exists(log_dir):
|
|
||||||
sh.mkdir("-p", log_dir)
|
|
||||||
|
|
||||||
# vim: ts=4 sw=4 sts=4 expandtab
|
# vim: ts=4 sw=4 sts=4 expandtab
|
||||||
|
Loading…
x
Reference in New Issue
Block a user