From 9699242da2cdd0d8ff7f3c066e5705b21d4df5a4 Mon Sep 17 00:00:00 2001 From: Natasha Singh Date: Thu, 30 Sep 2021 17:54:13 -0400 Subject: [PATCH] :fire: Remove sync job with old release coordinator --- creator/management/commands/schedule_jobs.py | 23 ---- creator/releases/tasks.py | 109 ------------------- 2 files changed, 132 deletions(-) diff --git a/creator/management/commands/schedule_jobs.py b/creator/management/commands/schedule_jobs.py index ef567962b..cac49b105 100644 --- a/creator/management/commands/schedule_jobs.py +++ b/creator/management/commands/schedule_jobs.py @@ -7,7 +7,6 @@ from creator.jobs.models import Job from creator.releases.tasks import ( - sync_releases_task, scan_releases, scan_tasks, ) @@ -53,7 +52,6 @@ def handle(self, *args, **options): logger.info( f"Found {len(jobs)} jobs scheduled on the Coordinator queue" ) - self.setup_coordinator_sync() self.setup_scan_releases() self.setup_scan_tasks() @@ -128,27 +126,6 @@ def setup_dataservice_sync(self): job.scheduled = True job.save() - def setup_coordinator_sync(self): - logger.info("Scheduling Release Coordinator Sync jobs") - name = "releases_sync" - description = "Syncronize Release Coordinator releases" - - self.releases_scheduler.cancel("releases_sync") - - self.releases_scheduler.schedule( - id=name, - description=description, - scheduled_time=datetime.utcnow(), - func=sync_releases_task, - repeat=None, - interval=600, - ) - job, created = Job.objects.get_or_create( - name=name, description=description, scheduler="releases" - ) - job.scheduled = True - job.save() - def setup_scan_releases(self): logger.info("Scheduling Scan Releases job") name = "scan_releases" diff --git a/creator/releases/tasks.py b/creator/releases/tasks.py index 0e38e7c92..55da47d1e 100644 --- a/creator/releases/tasks.py +++ b/creator/releases/tasks.py @@ -65,115 +65,6 @@ """ -@task(job="releases_sync") -def sync_releases_task(): - """ - Synchronize Release Coordinator releases with the Study Creator. - DeprecationWarning: Will remove this task once all Release Coordinator - operations are moved to the studdy creator. - """ - api = settings.COORDINATOR_URL - logger.info(f"Syncing releases with the Release Coordinator at {api}") - headers = client_headers(settings.AUTH0_SERVICE_AUD) - - resp = requests.post(api, json={"query": ALL_RELEASES}, headers=headers) - - releases = [n["node"] for n in resp.json()["data"]["allReleases"]["edges"]] - logger.info( - f"Retrieved {len(releases)} releases from the Release Coordinator" - ) - - # Create releases if they do not exist - new_releases = 0 - for r in releases: - # Don't update releases that are processing - if r["state"] in ["canceling", "running", "publishing"]: - continue - defaults = { - "uuid": r["uuid"], - "name": r["name"], - "version": r["version"], - "description": r["description"], - "is_major": r["isMajor"], - "created_at": r["createdAt"], - "state": r["state"], - } - release, created = Release.objects.update_or_create( - kf_id=r["kfId"], defaults=defaults - ) - - if created: - sync_new_release(release, r) - release.created_at = r["createdAt"] - release.save() - new_releases += 1 - - logger.info( - f"Imported {new_releases} new releases from the Release Coordinator" - ) - - -def sync_new_release(release, query): - # Add studies if the release did not previously exist - studies = [] - for study in query["studies"]["edges"]: - try: - studies.append(Study.objects.get(pk=study["node"]["kfId"])) - except Study.DoesNotExist: - logger.warning( - f"The study '{study['node']['kfId']}' does not exist. " - "Will not add to the release." - ) - release.studies.set(studies) - - # Try to find author by username - try: - release.creator = User.objects.get(username=query["author"]) - except User.DoesNotExist: - pass - - # Register tasks - tasks = [] - for t in query["tasks"]["edges"]: - task = t["node"] - - # Get the service or create it - service = task["taskService"] - defaults = { - "uuid": service["uuid"], - "name": service["name"], - "description": service["description"], - "created_at": service["createdAt"], - "url": service["url"], - } - release_service, created = ReleaseService.objects.get_or_create( - kf_id=service["kfId"], defaults=defaults - ) - try: - release_service.creator = User.objects.get( - username=service["author"] - ) - except User.DoesNotExist: - pass - - defaults = { - "uuid": task["uuid"], - "created_at": task["createdAt"], - "state": task["state"], - "release": release, - "release_service": release_service, - } - release_task, created = ReleaseTask.objects.update_or_create( - kf_id=task["kfId"], defaults=defaults - ) - tasks.append(release_task) - - logger.info( - f"Synced new release '{release.kf_id}' with " - f"{len(studies)} studies and {len(tasks)} tasks." - ) - - @task("release", related_models={Release: "release_id"}) def initialize_release(release_id=None): """