From 6cece17024535d535a317bfbf6432f280761c87b Mon Sep 17 00:00:00 2001 From: Matthew Jones Date: Thu, 5 May 2016 15:42:19 -0400 Subject: [PATCH] Purge cleanup_deleted tasks as they aren't needed This also adds a periodic static task to cleanup auth tokens --- .../0010_v300_create_system_job_templates.py | 23 +++---------------- awx/main/tasks.py | 11 ++++----- awx/settings/defaults.py | 4 ++++ 3 files changed, 11 insertions(+), 27 deletions(-) diff --git a/awx/main/migrations/0010_v300_create_system_job_templates.py b/awx/main/migrations/0010_v300_create_system_job_templates.py index 665b967ff3..e664a5d77f 100644 --- a/awx/main/migrations/0010_v300_create_system_job_templates.py +++ b/awx/main/migrations/0010_v300_create_system_job_templates.py @@ -40,26 +40,9 @@ def create_system_job_templates(apps, schema_editor): modified=now_dt, ) - sjt, created = SystemJobTemplate.objects.get_or_create( - job_type='cleanup_deleted', - defaults=dict( - name='Cleanup Deleted Data', - description='Remove deleted object history older than X days', - created=now_dt, - modified=now_dt, - polymorphic_ctype=sjt_ct, - ), - ) - if created: - sjt.schedules.create( - name='Cleanup Deleted Data Schedule', - rrule='DTSTART:%s RRULE:FREQ=WEEKLY;INTERVAL=1;BYDAY=MO' % now_str, - description='Automatically Generated Schedule', - enabled=True, - extra_data={'days': '30'}, - created=now_dt, - modified=now_dt, - ) + existing_cd_jobs = SystemJobTemplate.objects.filter(job_type='cleanup_deleted') + Schedule.objects.filter(unified_job_template__in=existing_cd_jobs).delete() + existing_cd_jobs.delete() sjt, created = SystemJobTemplate.objects.get_or_create( job_type='cleanup_activitystream', diff --git a/awx/main/tasks.py b/awx/main/tasks.py index 0ddb670c2b..568d39cb93 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -117,6 +117,10 @@ def run_label_cleanup(self): qs.delete() return labels_count +@task(bind=True) +def cleanup_authtokens(self): + AuthToken.objects.filter(expires__lt=now()).delete() + @task(bind=True) def tower_periodic_scheduler(self): def get_last_run(): @@ -1689,13 +1693,6 @@ class RunSystemJob(BaseTask): args.extend(['--older_than', str(json_vars['older_than'])]) if 'granularity' in json_vars: args.extend(['--granularity', str(json_vars['granularity'])]) - # Keeping this around in case we want to break this out - # if 'jobs' in json_vars and json_vars['jobs']: - # args.extend(['--jobs']) - # if 'project_updates' in json_vars and json_vars['project_updates']: - # args.extend(['--project-updates']) - # if 'inventory_updates' in json_vars and json_vars['inventory_updates']: - # args.extend(['--inventory-updates']) except Exception, e: logger.error("Failed to parse system job: " + str(e)) return args diff --git a/awx/settings/defaults.py b/awx/settings/defaults.py index 8546f49878..8349387a0d 100644 --- a/awx/settings/defaults.py +++ b/awx/settings/defaults.py @@ -349,6 +349,10 @@ CELERYBEAT_SCHEDULE = { 'task': 'awx.main.tasks.run_label_cleanup', 'schedule': timedelta(days=7) }, + 'authtoken_cleanup': { + 'task': 'awx.main.tasks.cleanup_authtokens', + 'schedule': timedelta(days=30) + }, } # Social Auth configuration.