コード例 #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.text = utils.get_json_result(status, result)
         resp.code = falcon.HTTP_200
     else:
         resp.code = falcon.HTTP_400
         resp.text = 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.text = "Job: " + str(uid) + " terminated"
         resp.code = falcon.HTTP_200
     else:
         resp.code = falcon.HTTP_400
         resp.text = str({'error': "no such job: " + str(uid)})
コード例 #3
0
ファイル: jobs.py プロジェクト: mehumaija/clusterMaker2
    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.text = 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_get(
     self,
     request: falcon.Request,
     response: falcon.Response,
     denomination: int,
 ) -> None:
     try:
         gift_card = self._use_case.fetch(Denomination(denomination))
     except GiftCardNotFoundForDenomination:
         raise errors.HTTPNotFound
     serialized_data = self._serializer.dump(gift_card)
     response.status = falcon.HTTP_200
     response.text = SuccessfulResponse(serialized_data).serialize()
コード例 #6
0
 def reject(response: Response, reason: str) -> None:
     """
     Complete request handling pipeline with an appropriate error.
     """
     http_status = falcon.HTTP_403
     response.text = json.dumps({
         'errors': [
             {
                 "title": "CSRF error",
                 "detail": str(reason),
                 'status': "Forbidden",
                 'code': http_status,
             },
         ],
     })
     response.status = http_status
     response.complete = True
コード例 #7
0
ファイル: algorithms.py プロジェクト: mehumaija/clusterMaker2
 def on_get(self, req: falcon.Request, resp: falcon.Response):
     resp.code = falcon.HTTP_200
     resp.text = '{"algorithms":' + json.dumps(list(
         self.algorithms.keys())) + '}'
コード例 #8
0
ファイル: jobs.py プロジェクト: mehumaija/clusterMaker2
def add_error(resp: falcon.Response, error: str):
    """ Construct an error return """
    #logging.error('error: %s'%(error))
    resp.status = falcon.HTTP_500
    resp.text = '{"error": ' + '"' + error + '"}'
コード例 #9
0
 def on_get(self, _req, resp: falcon.Response) -> None:
     # Falcon-Caching 1.0.1 does not cache resp.media.
     resp.text = json.dumps(self._fragmentarium.statistics())
コード例 #10
0
 def on_get(self, request: falcon.Request,
            response: falcon.Response) -> None:
     gift_cards = self._get_unused_use_case.fetch()
     serialized_data = self._dump_serializer.dump(gift_cards, many=True)
     response.text = SuccessfulResponse(data=serialized_data).serialize()
     response.status = falcon.HTTP_200
コード例 #11
0
 def on_get(self, request: falcon.Request,
            response: falcon.Response) -> None:
     assets = self._use_case.summarize()
     serialized_data = self._serializer.dump(assets)
     response.text = SuccessfulResponse(data=serialized_data).serialize()
     response.status = falcon.HTTP_200
コード例 #12
0
 def on_get(self, request: falcon.Request,
            response: falcon.Response) -> None:
     denominations = self._use_case.fetch()
     response.status = falcon.HTTP_200
     response.text = SuccessfulResponse(denominations).serialize()