diff --git a/gateway/api/ray.py b/gateway/api/ray.py index 2258e22c7..61edd2ba4 100644 --- a/gateway/api/ray.py +++ b/gateway/api/ray.py @@ -87,28 +87,27 @@ def submit(self, job: Job) -> Optional[str]: except KeyError: pass - f = open(extract_folder + "/launcher.py", "w") - f.write( - ''' + with open(extract_folder + "/launcher.py", "w", encoding="utf-8") as f: + f.write( + """ import subprocess from subprocess import Popen import sys from quantum_serverless import set_status with Popen( - ["python", sys.argv[1]], + ['python', sys.argv[1]], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, ) as pipe: - status = "SUCCEEDED" + status = 'SUCCEEDED' if pipe.wait(): - status = "FAILED" + status = 'FAILED' output, _ = pipe.communicate() print(output) set_status(status) - ''' - ) - f.close() + """ + ) ray_job_id = retry_function( callback=lambda: self.client.submit_job( diff --git a/gateway/api/views.py b/gateway/api/views.py index 712fede78..6ba61708a 100644 --- a/gateway/api/views.py +++ b/gateway/api/views.py @@ -181,7 +181,6 @@ def run(self, request): status=Job.QUEUED, config=jobconfig, ) - job.save() carrier = {} TraceContextTextMapPropagator().inject(carrier) diff --git a/gateway/main/signals.py b/gateway/main/signals.py index 47a11e8af..8b3e8c4c7 100644 --- a/gateway/main/signals.py +++ b/gateway/main/signals.py @@ -1,3 +1,4 @@ +"""Model signal processing.""" from django.db.models.signals import post_save from django.dispatch import receiver from api.models import Job @@ -6,7 +7,8 @@ @receiver(post_save, sender=Job) -def save_job(sender, instance, created, **kwargs): +def save_job(sender, instance, created, **kwargs): # pylint: disable=unused-argument + """procss save Job model entry event.""" print("save_job") print(instance) print("Free") diff --git a/gateway/main/urls.py b/gateway/main/urls.py index ad358e29e..7cb220cf3 100644 --- a/gateway/main/urls.py +++ b/gateway/main/urls.py @@ -19,11 +19,12 @@ from django.urls import path, include, re_path from django.views.generic import TemplateView from rest_framework import routers -from .signals import save_job - from api.views import KeycloakLogin, KeycloakUsersView import probes.views +from .signals import save_job # pylint: disable=unused-import + + router = routers.DefaultRouter()