Exemplo n.º 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)
Exemplo n.º 2
0
    def post(self, request):
        name = request.DATA['name']
        if (name 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)
        logger.info('meta: %s' % request.DATA['meta'])
        json_meta = json.dumps(request.DATA['meta'])
        logger.info('json_meta: %s' % json_meta)
        logger.info('request: %s' % request.DATA)

        ts = int(float(request.DATA['ts']))
        ts_dto = datetime.utcfromtimestamp(float(ts)).replace(second=0,
                                                              microsecond=0,
                                                              tzinfo=utc)
        td = TaskDefinition(name=name, ts=ts_dto, frequency=frequency,
                            json_meta=json_meta)
        td.save()
        return Response()
Exemplo n.º 3
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)

            crontab, 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, json_meta=json_meta,
                                enabled=enabled)
            td.save()
            self._refresh_crontab()
            return Response(TaskDefinitionSerializer(td).data)
Exemplo n.º 4
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)
Exemplo n.º 5
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)