Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔥 Remove sync job with old release coordinator #774

Merged
merged 1 commit into from
Sep 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions creator/management/commands/schedule_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

from creator.jobs.models import Job
from creator.releases.tasks import (
sync_releases_task,
scan_releases,
scan_tasks,
)
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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"
Expand Down
109 changes: 0 additions & 109 deletions creator/releases/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down