コード例 #1
0
    def post(self, request):
        with self._handle_exception(request):
            name = request.data['name']
            if (TaskDefinition.objects.filter(name=name).exists()):
                msg = ('Another task exists with the same name({}). Choose '
                       'a different name'.format(name))
                handle_exception(Exception(msg), request)

            task_type = request.data['task_type']
            if (task_type not in self.valid_tasks):
                e_msg = (
                    'Unknown task type: {} cannot be scheduled'.format(name))
                handle_exception(Exception(e_msg), request)

            crontab, crontabwindow, meta = self._validate_input(request)
            json_meta = json.dumps(meta)
            enabled = self._validate_enabled(request)
            td = TaskDefinition(name=name,
                                task_type=task_type,
                                crontab=crontab,
                                crontabwindow=crontabwindow,
                                json_meta=json_meta,
                                enabled=enabled)
            td.save()
            self._refresh_crontab()
            return Response(TaskDefinitionSerializer(td).data)
コード例 #2
0
 def get(self, request, *args, **kwargs):
     try:
         data = TaskDefinition.objects.get(id=self.kwargs['tdid'])
         serialized_data = TaskDefinitionSerializer(data)
         return Response(serialized_data.data)
     except:
         return Response()
コード例 #3
0
    def post(self, request):
        name = request.DATA['name']
        task_type = request.DATA['task_type']
        if (task_type not in self.valid_tasks):
            e_msg = ('Unknown task type: %s cannot be scheduled' % name)
            handle_exception(Exception(e_msg), request)

        frequency = None
        if ('frequency' in request.DATA):
            frequency = int(request.DATA['frequency'])
            if (frequency < 60):
                frequency = None
            else:
                frequency = frequency - (frequency % 60)
        json_meta = json.dumps(request.DATA['meta'])

        ts = int(float(request.DATA['ts']))
        ts_dto = datetime.utcfromtimestamp(float(ts)).replace(second=0,
                                                              microsecond=0,
                                                              tzinfo=utc)
        td = TaskDefinition(name=name,
                            task_type=task_type,
                            ts=ts_dto,
                            frequency=frequency,
                            json_meta=json_meta)
        td.save()
        return Response(TaskDefinitionSerializer(td).data)
コード例 #4
0
 def put(self, request, tdid):
     with self._handle_exception(request):
         tdo = self._task_def(request, tdid)
         tdo.enabled = self._validate_enabled(request)
         tdo.crontab, new_meta = self._validate_input(request)
         meta = json.loads(tdo.json_meta)
         meta.update(new_meta)
         tdo.json_meta = json.dumps(meta)
         tdo.save()
         self._refresh_crontab()
         return Response(TaskDefinitionSerializer(tdo).data)
コード例 #5
0
 def put(self, request, tdid):
     with self._handle_exception(request):
         tdo = self._task_def(request, tdid)
         enabled = request.data.get('enabled', True)
         if (type(enabled) != bool):
             e_msg = ('enabled flag must be a boolean and not %s' %
                      type(enabled))
             handle_exception(Exception(e_msg), request)
         tdo.enabled = enabled
         tdo.frequency, new_meta = self._validate_input(request)
         meta = json.loads(tdo.json_meta)
         meta.update(new_meta)
         tdo.json_meta = json.dumps(meta)
         tdo.save()
         return Response(TaskDefinitionSerializer(tdo).data)
コード例 #6
0
    def post(self, request):
        with self._handle_exception(request):
            name = request.data['name']
            if (TaskDefinition.objects.filter(name=name).exists()):
                msg = ('Another task exists with the same name(%s). Choose '
                       'a different name' % name)
                handle_exception(Exception(msg), request)

            task_type = request.data['task_type']
            if (task_type not in self.valid_tasks):
                e_msg = ('Unknown task type: %s cannot be scheduled' % name)
                handle_exception(Exception(e_msg), request)

            frequency, meta = self._validate_input(request)
            json_meta = json.dumps(meta)

            ts = int(float(request.data['ts']))
            ts_dto = datetime.utcfromtimestamp(
                float(ts)).replace(second=0, microsecond=0, tzinfo=utc)
            td = TaskDefinition(name=name, task_type=task_type, ts=ts_dto,
                                frequency=frequency, json_meta=json_meta)
            td.save()
            return Response(TaskDefinitionSerializer(td).data)
コード例 #7
0
 def put(self, request, tdid):
     tdo = self._task_def(request, tdid)
     enabled = request.DATA['enabled']
     tdo.enabled = enabled
     tdo.save()
     return Response(TaskDefinitionSerializer(tdo).data)