Esempio n. 1
0
 def post(self, taskId=None):
     # create 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("You must not specify task.id")
     
     t = task.Task()
     t.fromApiDict( data )
     
     with self.db:
         taskId = self.db.insertTask( t )
     
     return self._taskIdToResponse( taskId, status_code=201) 
    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())
Esempio n. 3
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)
Esempio n. 4
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) 
Esempio n. 5
0
 def put(self, taskId):
     # replace task
     raise errors.ApiUsageError("Not implemented")
Esempio n. 6
0
 def patch(self, taskId=None, depId=None):
     # update task
     raise errors.ApiUsageError("Not implemented")
 def delete(self, taskId):
     raise errors.ApiUsageError("Not implemented yet")