Exemplo n.º 1
0
    def get(self, taskId=None, depId=None):
        data = None
        with self.db:
            t = self.db.getTask(taskId)
        if t == None:
            raise errors.ApiNotFoundError("Task not found")

        if depId is None:
            # get all dependencies
            data = []
            for depId in t.depends:
                with self.db:
                    dt = self.db.getTask(depId)
                if dt != None:
                    data.append(dt.toApiDict())
        else:
            # get specific task
            with self.db:
                t = self.db.getTask(depId)
            if t != None:
                data = t.toApiDict()
            else:
                raise errors.ApiNotFoundError("Task not a dependency")

        return jsonify(data)
Exemplo n.º 2
0
 def delete(self, taskId):
     with self.db:
         t = self.db.getTask( taskId )
         if t == None:
             raise errors.ApiNotFoundError("Failed to delete Task: not found")
         self.db.deleteTask( t )
     return jsonify(None)
Exemplo n.º 3
0
 def _taskIdToResponse(self, taskId, status_code=200 ):
     with self.db:
         t = self.db.getTask( taskId )
     if t == None:
         raise errors.ApiNotFoundError("Task {} not found".format(taskId) )
     r = jsonify( t.toApiDict() )
     r.status_code = status_code
     return r
Exemplo n.º 4
0
 def delete(self, taskId=None, depId=None):
     with self.db:
         t = self.db.getTask(taskId)
     if t == None:
         raise errors.ApiNotFoundError("Task not found")
     with self.db:
         self.db.removeTaskDependency(t.id, depId)
     return jsonify(None)
Exemplo n.º 5
0
 def get(self, taskId):
     data = None
     if taskId is None:
         # get all tasks
         data = []
         with self.db:
             tasks = self.db.getTasks()
         for t in tasks:
             data.append( t.toApiDict() )
     else:
         # get specific task
         with self.db:
             t = self.db.getTask( taskId )
         if t != None:
             data = t.toApiDict()
         else:
             raise errors.ApiNotFoundError("Task not found")
         
     return jsonify( data )
    def post(self, taskId=None):
        if not request.is_json:
            raise errors.ApiUsageError("Must be json mime type")
        data = request.get_json()
        if "worker_id" not in data:
            raise errors.ApiUsageError("You must specify request.worker_id")
        doPeek = False
        if "peek" in data:
            doPeek = bool(data["peek"])

        sched = scheduler.Scheduler(self.db)
        try:
            with sched:
                t = sched.getNextTask(data["worker_id"], peek=doPeek)
        except errors.SchedulerError as e:
            raise errors.ApiError(str(e))
        if t == None:
            raise errors.ApiNotFoundError("No task to be scheduled")

        return jsonify(t.toApiDict())
Exemplo n.º 7
0
    def post(self, taskId=None, depId=None):
        # create dependency
        if not request.is_json:
            raise errors.ApiUsageError("Must be json mime type")
        data = request.get_json()
        if "id" not in data:
            raise errors.ApiUsageError("You must specify task.id")

        with self.db:
            t = self.db.getTask(taskId)
        if t == None:
            raise errors.ApiNotFoundError("Task not found")

        dt = task.Task()
        dt.fromApiDict(data)

        try:
            with self.db:
                self.db.addTaskDependency(t.id, dt.id)
        except errors.DatabaseError as e:
            raise errors.ApiUsageError(str(e)) from None

        return self._taskIdToResponse(dt.id, status_code=201)
Exemplo n.º 8
0
    def patch(self, taskId):
        # update task
        if not request.is_json:
            raise errors.ApiUsageError("Must be json mime type")
        data = request.get_json()
        if "id" in data:
            raise errors.ApiUsageError("task.id cannot be updated")
        if "depends" in data:
            raise errors.ApiUsageError("task.depends cannot be updated, use the /tasks/1/depends endpoint")

        try:
            updateAttrs = task.Task.apiKeysToAttributes( data.keys() )
        except KeyError as e:
            raise errors.ApiUsageError("Invalid key: {}".format(e.message) ) from None
        
        with self.db:
            t = self.db.getTask( taskId )
            if t == None:
                raise errors.ApiNotFoundError("Task not found")
            
            t.fromApiDict( data )
            self.db.updateTask(t, updateAttrs )
        
        return self._taskIdToResponse( taskId, status_code=200)