예제 #1
0
 def fetch_results(self, uid: UUID, req: falcon.Request,
                   resp: falcon.Response):
     if uid in self.myjobs:
         (proc, status, result) = self.myjobs[uid]
         # Add our response
         resp.body = utils.get_json_result(status, result)
         resp.code = falcon.HTTP_200
     else:
         resp.code = falcon.HTTP_400
         resp.body = str({'error': "no such job: " + str(uid)})
예제 #2
0
 def terminate(self, uid: UUID, req: falcon.Request, resp: falcon.Response):
     # Terminate the running process
     if uid in self.myjobs:
         (proc, status, result) = self.myjobs[uid]
         proc.terminate()
         self.jobs.remove_job(uid)
         del self.myjobs[uid]
         resp.body = "Job: " + str(uid) + " terminated"
         resp.code = falcon.HTTP_200
     else:
         resp.code = falcon.HTTP_400
         resp.body = str({'error': "no such job: " + str(uid)})
예제 #3
0
파일: jobs.py 프로젝트: RBVI/REST-API
    def on_get(self, req: falcon.Request, resp: falcon.Response, job_id: str):
        """ Handles GET requests /status and /fetch """
        path = req.path
        #print('path: '+path)
        #print('job_id: '+job_id)
        #logging.info('path: %s, job_id: %s [%d]'%(path,job_id,os.getpid()))
        if path.startswith("/status/"):
            uid = get_job_id(job_id)
            if uid in self.active_jobs:
                resp.code = falcon.HTTP_200
                resp.body = str(self.active_jobs[uid].get_status(uid))
                return
            add_error(resp, "No such job")
            return

        if path.startswith("/fetch/"):
            uid = get_job_id(job_id)
            if uid in self.active_jobs:
                self.active_jobs[uid].fetch_results(uid, req, resp)
                return
            add_error(resp, "No such job")
            return

        if path.startswith("/terminate/"):
            uid = get_job_id(job_id)
            if uid in self.active_jobs:
                self.active_jobs[uid].terminate(uid, req, resp)
                return
            add_error(resp, "No such job")
            return

        if path.startswith("/jobs"):
            return
예제 #4
0
    def on_post(self, req: falcon.Request, resp: falcon.Response):
        """ Get data and arguments """
        result = self.manager.dict()
        status = self.manager.dict()

        # Get our parameters
        args = self.get_args(req)

        # We need to do the load here because we can't pass a stream to our
        # child process
        if hasattr(req.get_param('data'), 'file'):
            # Python requests adds an extra dict
            args['json_data'] = json.load(req.get_param('data').file)
        else:
            # Assume it's just straight text
            args['json_data'] = json.loads(req.get_param('data'))

        f = open("/var/tmp/wsgi.log", "w")
        f.write(str(args['json_data']))

        uuid = self.jobs.create_job(req.path, self)
        proc = Process(target=self.community_detection,
                       args=(args, status, result))
        self.myjobs[uuid] = (proc, status, result)
        proc.start()
        resp.code = falcon.HTTP_200
        resp.text = json.dumps({'job_id': str(uuid)})
예제 #5
0
    def on_post(self, req: falcon.Request, resp: falcon.Response):
        """ Get data and arguments """
        result = self.manager.dict()
        status = self.manager.dict()

        # Get our parameters
        args = self.get_args(req)

        # We need to do the load here because we can't pass a stream to our
        # child process
        args['json_data'] = json.load(req.get_param('data').file)

        uuid = self.jobs.create_job(req.path, self)
        proc = Process(target=self.community_detection,
                       args=(args, status, result))
        self.myjobs[uuid] = (proc, status, result)
        proc.start()
        resp.code = falcon.HTTP_200
        resp.body = json.dumps({'job_id': str(uuid)})
예제 #6
0
 def on_get(self, req: falcon.Request, resp: falcon.Response):
     resp.code = falcon.HTTP_200
     resp.text = '{"algorithms":' + json.dumps(list(
         self.algorithms.keys())) + '}'