mirror of
https://github.com/ansible/awx.git
synced 2026-03-20 18:37:39 -02:30
Merge pull request #4186 from cchurch/cleanup-jobs-output
Display count of skipped/deleted for cleanup jobs
This commit is contained in:
@@ -48,6 +48,7 @@ class Command(NoArgsCommand):
|
|||||||
def cleanup_jobs(self):
|
def cleanup_jobs(self):
|
||||||
#jobs_qs = Job.objects.exclude(status__in=('pending', 'running'))
|
#jobs_qs = Job.objects.exclude(status__in=('pending', 'running'))
|
||||||
#jobs_qs = jobs_qs.filter(created__lte=self.cutoff)
|
#jobs_qs = jobs_qs.filter(created__lte=self.cutoff)
|
||||||
|
skipped, deleted = 0, 0
|
||||||
for job in Job.objects.all():
|
for job in Job.objects.all():
|
||||||
job_display = '"%s" (started %s, %d host summaries, %d events)' % \
|
job_display = '"%s" (started %s, %d host summaries, %d events)' % \
|
||||||
(unicode(job), unicode(job.created),
|
(unicode(job), unicode(job.created),
|
||||||
@@ -55,16 +56,21 @@ class Command(NoArgsCommand):
|
|||||||
if job.status in ('pending', 'waiting', 'running'):
|
if job.status in ('pending', 'waiting', 'running'):
|
||||||
action_text = 'would skip' if self.dry_run else 'skipping'
|
action_text = 'would skip' if self.dry_run else 'skipping'
|
||||||
self.logger.debug('%s %s job %s', action_text, job.status, job_display)
|
self.logger.debug('%s %s job %s', action_text, job.status, job_display)
|
||||||
|
skipped += 1
|
||||||
elif job.created >= self.cutoff:
|
elif job.created >= self.cutoff:
|
||||||
action_text = 'would skip' if self.dry_run else 'skipping'
|
action_text = 'would skip' if self.dry_run else 'skipping'
|
||||||
self.logger.debug('%s %s', action_text, job_display)
|
self.logger.debug('%s %s', action_text, job_display)
|
||||||
|
skipped += 1
|
||||||
else:
|
else:
|
||||||
action_text = 'would delete' if self.dry_run else 'deleting'
|
action_text = 'would delete' if self.dry_run else 'deleting'
|
||||||
self.logger.info('%s %s', action_text, job_display)
|
self.logger.info('%s %s', action_text, job_display)
|
||||||
if not self.dry_run:
|
if not self.dry_run:
|
||||||
job.delete()
|
job.delete()
|
||||||
|
deleted += 1
|
||||||
|
return skipped, deleted
|
||||||
|
|
||||||
def cleanup_ad_hoc_commands(self):
|
def cleanup_ad_hoc_commands(self):
|
||||||
|
skipped, deleted = 0, 0
|
||||||
for ad_hoc_command in AdHocCommand.objects.all():
|
for ad_hoc_command in AdHocCommand.objects.all():
|
||||||
ad_hoc_command_display = '"%s" (started %s, %d events)' % \
|
ad_hoc_command_display = '"%s" (started %s, %d events)' % \
|
||||||
(unicode(ad_hoc_command), unicode(ad_hoc_command.created),
|
(unicode(ad_hoc_command), unicode(ad_hoc_command.created),
|
||||||
@@ -72,65 +78,86 @@ class Command(NoArgsCommand):
|
|||||||
if ad_hoc_command.status in ('pending', 'waiting', 'running'):
|
if ad_hoc_command.status in ('pending', 'waiting', 'running'):
|
||||||
action_text = 'would skip' if self.dry_run else 'skipping'
|
action_text = 'would skip' if self.dry_run else 'skipping'
|
||||||
self.logger.debug('%s %s ad hoc command %s', action_text, ad_hoc_command.status, ad_hoc_command_display)
|
self.logger.debug('%s %s ad hoc command %s', action_text, ad_hoc_command.status, ad_hoc_command_display)
|
||||||
|
skipped += 1
|
||||||
elif ad_hoc_command.created >= self.cutoff:
|
elif ad_hoc_command.created >= self.cutoff:
|
||||||
action_text = 'would skip' if self.dry_run else 'skipping'
|
action_text = 'would skip' if self.dry_run else 'skipping'
|
||||||
self.logger.debug('%s %s', action_text, ad_hoc_command_display)
|
self.logger.debug('%s %s', action_text, ad_hoc_command_display)
|
||||||
|
skipped += 1
|
||||||
else:
|
else:
|
||||||
action_text = 'would delete' if self.dry_run else 'deleting'
|
action_text = 'would delete' if self.dry_run else 'deleting'
|
||||||
self.logger.info('%s %s', action_text, ad_hoc_command_display)
|
self.logger.info('%s %s', action_text, ad_hoc_command_display)
|
||||||
if not self.dry_run:
|
if not self.dry_run:
|
||||||
ad_hoc_command.delete()
|
ad_hoc_command.delete()
|
||||||
|
deleted += 1
|
||||||
|
return skipped, deleted
|
||||||
|
|
||||||
def cleanup_project_updates(self):
|
def cleanup_project_updates(self):
|
||||||
|
skipped, deleted = 0, 0
|
||||||
for pu in ProjectUpdate.objects.all():
|
for pu in ProjectUpdate.objects.all():
|
||||||
pu_display = '"%s" (started %s)' % (unicode(pu), unicode(pu.created))
|
pu_display = '"%s" (started %s)' % (unicode(pu), unicode(pu.created))
|
||||||
if pu.status in ('pending', 'waiting', 'running'):
|
if pu.status in ('pending', 'waiting', 'running'):
|
||||||
action_text = 'would skip' if self.dry_run else 'skipping'
|
action_text = 'would skip' if self.dry_run else 'skipping'
|
||||||
self.logger.debug('%s %s project update %s', action_text, pu.status, pu_display)
|
self.logger.debug('%s %s project update %s', action_text, pu.status, pu_display)
|
||||||
if pu in (pu.project.current_update, pu.project.last_update) and pu.project.scm_type:
|
skipped += 1
|
||||||
|
elif pu in (pu.project.current_update, pu.project.last_update) and pu.project.scm_type:
|
||||||
action_text = 'would skip' if self.dry_run else 'skipping'
|
action_text = 'would skip' if self.dry_run else 'skipping'
|
||||||
self.logger.debug('%s %s', action_text, pu_display)
|
self.logger.debug('%s %s', action_text, pu_display)
|
||||||
|
skipped += 1
|
||||||
elif pu.created >= self.cutoff:
|
elif pu.created >= self.cutoff:
|
||||||
action_text = 'would skip' if self.dry_run else 'skipping'
|
action_text = 'would skip' if self.dry_run else 'skipping'
|
||||||
self.logger.debug('%s %s', action_text, pu_display)
|
self.logger.debug('%s %s', action_text, pu_display)
|
||||||
|
skipped += 1
|
||||||
else:
|
else:
|
||||||
action_text = 'would delete' if self.dry_run else 'deleting'
|
action_text = 'would delete' if self.dry_run else 'deleting'
|
||||||
self.logger.info('%s %s', action_text, pu_display)
|
self.logger.info('%s %s', action_text, pu_display)
|
||||||
if not self.dry_run:
|
if not self.dry_run:
|
||||||
pu.delete()
|
pu.delete()
|
||||||
|
deleted += 1
|
||||||
|
return skipped, deleted
|
||||||
|
|
||||||
def cleanup_inventory_updates(self):
|
def cleanup_inventory_updates(self):
|
||||||
|
skipped, deleted = 0, 0
|
||||||
for iu in InventoryUpdate.objects.all():
|
for iu in InventoryUpdate.objects.all():
|
||||||
iu_display = '"%s" (started %s)' % (unicode(iu), unicode(iu.created))
|
iu_display = '"%s" (started %s)' % (unicode(iu), unicode(iu.created))
|
||||||
if iu.status in ('pending', 'waiting', 'running'):
|
if iu.status in ('pending', 'waiting', 'running'):
|
||||||
action_text = 'would skip' if self.dry_run else 'skipping'
|
action_text = 'would skip' if self.dry_run else 'skipping'
|
||||||
self.logger.debug('%s %s inventory update %s', action_text, iu.status, iu_display)
|
self.logger.debug('%s %s inventory update %s', action_text, iu.status, iu_display)
|
||||||
if iu in (iu.inventory_source.current_update, iu.inventory_source.last_update) and iu.inventory_source.source:
|
skipped += 1
|
||||||
|
elif iu in (iu.inventory_source.current_update, iu.inventory_source.last_update) and iu.inventory_source.source:
|
||||||
action_text = 'would skip' if self.dry_run else 'skipping'
|
action_text = 'would skip' if self.dry_run else 'skipping'
|
||||||
self.logger.debug('%s %s', action_text, iu_display)
|
self.logger.debug('%s %s', action_text, iu_display)
|
||||||
|
skipped += 1
|
||||||
elif iu.created >= self.cutoff:
|
elif iu.created >= self.cutoff:
|
||||||
action_text = 'would skip' if self.dry_run else 'skipping'
|
action_text = 'would skip' if self.dry_run else 'skipping'
|
||||||
self.logger.debug('%s %s', action_text, iu_display)
|
self.logger.debug('%s %s', action_text, iu_display)
|
||||||
|
skipped += 1
|
||||||
else:
|
else:
|
||||||
action_text = 'would delete' if self.dry_run else 'deleting'
|
action_text = 'would delete' if self.dry_run else 'deleting'
|
||||||
self.logger.info('%s %s', action_text, iu_display)
|
self.logger.info('%s %s', action_text, iu_display)
|
||||||
if not self.dry_run:
|
if not self.dry_run:
|
||||||
iu.delete()
|
iu.delete()
|
||||||
|
deleted += 1
|
||||||
|
return skipped, deleted
|
||||||
|
|
||||||
def cleanup_management_jobs(self):
|
def cleanup_management_jobs(self):
|
||||||
|
skipped, deleted = 0, 0
|
||||||
for sj in SystemJob.objects.all():
|
for sj in SystemJob.objects.all():
|
||||||
sj_display = '"%s" (started %s)' % (unicode(sj), unicode(sj.created))
|
sj_display = '"%s" (started %s)' % (unicode(sj), unicode(sj.created))
|
||||||
if sj.status in ('pending', 'waiting', 'running'):
|
if sj.status in ('pending', 'waiting', 'running'):
|
||||||
action_text = 'would skip' if self.dry_run else 'skipping'
|
action_text = 'would skip' if self.dry_run else 'skipping'
|
||||||
self.logger.debug('%s %s system_job %s', action_text, sj.status, sj_display)
|
self.logger.debug('%s %s system_job %s', action_text, sj.status, sj_display)
|
||||||
|
skipped += 1
|
||||||
elif sj.created >= self.cutoff:
|
elif sj.created >= self.cutoff:
|
||||||
action_text = 'would skip' if self.dry_run else 'skipping'
|
action_text = 'would skip' if self.dry_run else 'skipping'
|
||||||
self.logger.debug('%s %s', action_text, sj_display)
|
self.logger.debug('%s %s', action_text, sj_display)
|
||||||
|
skipped += 1
|
||||||
else:
|
else:
|
||||||
action_text = 'would delete' if self.dry_run else 'deleting'
|
action_text = 'would delete' if self.dry_run else 'deleting'
|
||||||
self.logger.info('%s %s', action_text, sj_display)
|
self.logger.info('%s %s', action_text, sj_display)
|
||||||
if not self.dry_run:
|
if not self.dry_run:
|
||||||
sj.delete()
|
sj.delete()
|
||||||
|
deleted += 1
|
||||||
|
return skipped, deleted
|
||||||
|
|
||||||
def init_logging(self):
|
def init_logging(self):
|
||||||
log_levels = dict(enumerate([logging.ERROR, logging.INFO,
|
log_levels = dict(enumerate([logging.ERROR, logging.INFO,
|
||||||
@@ -161,4 +188,8 @@ class Command(NoArgsCommand):
|
|||||||
models_to_cleanup.update(model_names)
|
models_to_cleanup.update(model_names)
|
||||||
for m in model_names:
|
for m in model_names:
|
||||||
if m in models_to_cleanup:
|
if m in models_to_cleanup:
|
||||||
getattr(self, 'cleanup_%s' % m)()
|
skipped, deleted = getattr(self, 'cleanup_%s' % m)()
|
||||||
|
if self.dry_run:
|
||||||
|
self.logger.log(99, '%s: %d would be deleted, %d would be skipped.', m.replace('_', ' '), deleted, skipped)
|
||||||
|
else:
|
||||||
|
self.logger.log(99, '%s: %d deleted, %d skipped.', m.replace('_', ' '), deleted, skipped)
|
||||||
|
|||||||
Reference in New Issue
Block a user