Commit 2572cac6 authored by Andrey Vertiprahov's avatar Andrey Vertiprahov
Browse files

Fix cleanup jobs.

parent fc31c117
Pipeline #27774 passed with stages
in 3 minutes and 49 seconds
...@@ -48,7 +48,7 @@ def main(): ...@@ -48,7 +48,7 @@ def main():
) )
clean.add_argument("--before", help="DateTime before log will be deleted", required=False) clean.add_argument("--before", help="DateTime before log will be deleted", required=False)
clean.add_argument( clean.add_argument(
"--last", type=int, help="Cleanup joblog to last N record", required=False, default=10 "--save-last", type=int, help="Cleanup joblog to last N record", required=False, default=10
) )
args = parser.parse_args() args = parser.parse_args()
...@@ -113,21 +113,30 @@ def joblog_clean(args): ...@@ -113,21 +113,30 @@ def joblog_clean(args):
before = datetime.datetime.strptime(args.before, "%Y-%m-%d %H:%M") before = datetime.datetime.strptime(args.before, "%Y-%m-%d %H:%M")
cleaned_job = JobLog.filter(start_ts__gte=before, is_complete=True) cleaned_job = JobLog.filter(start_ts__gte=before, is_complete=True)
print(" %d JobLog before %s will be cleaned" % (cleaned_job.count(), args.before)) print(" %d JobLog before %s will be cleaned" % (cleaned_job.count(), args.before))
elif args.last and joblog_count > args.last: elif args.save_last and joblog_count > args.save_last:
cleaned_job = ( cleaned_job = (
JobLog.filter(is_complete=True) JobLog.filter(is_complete=True)
.order_by(JobLog.start_ts) .order_by(JobLog.start_ts)
.limit(joblog_count - args.last) .limit(joblog_count - args.save_last)
)
print(
" %d/%d JobLog more %s will be cleaned"
% (cleaned_job.count(), joblog_count, args.save_last)
)
elif args.save_last and joblog_count <= args.save_last:
die(
"JobLog count is %d less (or equal) that save param: %d"
% (joblog_count, args.save_last)
) )
print(" %d JobLog more %s will be cleaned" % (cleaned_job.count(), args.last))
else: else:
die("Please set cleanup policy") die("Please set cleanup policy")
print(" %d JobLog will be Remove..\n" % cleaned_job.count()) print(" %d JobLog will be Remove..\n" % cleaned_job.count())
for i in reversed(range(1, 10)): for i in reversed(range(1, 10)):
print("%d\n" % i) print("%d\n" % i)
time.sleep(1) time.sleep(1)
for job in cleaned_job: for x, job in enumerate(cleaned_job):
job.delete().execute() print(x, job)
job.delete_instance()
if __name__ == "__main__": if __name__ == "__main__":
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment