Ejemplo n.º 1
0
    def update_schedule(self, request, id):
        datasource = self.get_object()

        self.check_object_permissions(self.request, datasource)

        # If a schedule already exists for this datasource, then delete it
        if "schedule" in datasource:
            delete_task(datasource.schedule.task_name)

        task_name = create_task("refresh_datasource_data", request.data,
                                {"datasource_id": id})
        request.data["task_name"] = task_name

        serializer = DatasourceSerializer(datasource,
                                          data={"schedule": request.data},
                                          partial=True)
        serializer.is_valid()
        serializer.save()

        logger.info(
            "datasource.update_schedule",
            extra={
                "user": self.request.user.email,
                "payload": self.request.data
            },
        )

        return Response(serializer.data)
Ejemplo n.º 2
0
    def put(self, request, format=None):
        datalabs = [ObjectId(datalab) for datalab in request.data.get("datalabs", [])]
        scheduled = request.data.get("scheduled")

        dump = Dump.objects.all()
        if len(dump) > 0:
            dump = dump[0]
            dump.datalabs = datalabs
        else:
            dump = Dump(datalabs=datalabs)

        dump.save()

        if scheduled and not dump.task_name:
            schedule = {
                "frequency": "daily",
                "time": dt.utcnow()
                .replace(hour=21, minute=0)
                .strftime("%Y-%m-%dT%H:%M:%S.%fZ"),
            }
            task_name = create_task("dump_datalab_data", schedule)
            dump.task_name = task_name
            dump.save()

        elif not scheduled and dump.task_name:
            delete_task(dump.task_name)
            dump.task_name = None
            dump.save()

        is_force = request.query_params.get("force")
        if is_force:
            dump_datalab_data.delay()

        return Response()
Ejemplo n.º 3
0
    def schedule(self, request, id=None):
        action = self.get_object()
        self.check_object_permissions(request, action)

        # If a schedule already exists for this action, then delete it
        if "schedule" in action:
            delete_task(action.schedule.task_name)

        if request.method == "PUT":
            task_name = create_task("workflow_send_email", request.data,
                                    {"action_id": id})
            request.data["task_name"] = task_name

            action.schedule = Schedule(**request.data)

            logger.info(
                "action.update_schedule",
                extra={
                    "user": self.request.user.email,
                    "payload": self.request.data
                },
            )

        if request.method == "DELETE" and "schedule" in action:
            delete_task(action.schedule.task_name)
            action.schedule = None

            logger.info(
                "action.delete_schedule",
                extra={
                    "user": self.request.user.email,
                    "payload": self.request.data
                },
            )

        action.save()

        serializer = ActionSerializer(action)
        return Response(serializer.data)