示例#1
0
def delete_file(path, checksum, **kwargs):
    from sentry.models.file import get_storage, FileBlob
    from sentry.app import locks
    from sentry.utils.retries import TimedRetryPolicy

    lock = locks.get(f"fileblob:upload:{checksum}", duration=60 * 10)
    with TimedRetryPolicy(60)(lock.acquire):
        if not FileBlob.objects.filter(checksum=checksum).exists():
            get_storage().delete(path)
示例#2
0
文件: files.py 项目: Kayle009/sentry
def delete_file(path, checksum, **kwargs):
    from sentry.models.file import get_storage, FileBlob
    from sentry.app import locks
    from sentry.utils.retries import TimedRetryPolicy

    lock = locks.get(u'fileblob:upload:{}'.format(checksum), duration=60 * 10)
    with TimedRetryPolicy(60)(lock.acquire):
        if not FileBlob.objects.filter(checksum=checksum).exists():
            get_storage().delete(path)
示例#3
0
    def generate_chart(self,
                       style: ChartType,
                       data: Any,
                       upload: bool = True) -> Union[str, bytes]:
        request_id = uuid4().hex

        data = {
            "requestId": request_id,
            "style": style.value,
            "data": data,
        }

        with Session() as session:
            with sentry_sdk.start_span(
                    op="charts.chartcuterie.generate_chart",
                    description=type(self).__name__,
            ):
                resp = session.request(
                    method="POST",
                    url=urljoin(self.service_url, "render"),
                    json=data,
                )

                if resp.status_code == 503 and settings.DEBUG:
                    logger.info(
                        "You may need to build the chartcuterie config using `yarn build-chartcuterie-config`"
                    )

                if resp.status_code != 200:
                    raise RuntimeError(
                        f"Chartcuterie responded with {resp.status_code}: {resp.text}"
                    )

        if not upload:
            return resp.content

        file_name = f"{request_id}.png"

        with sentry_sdk.start_span(
                op="charts.chartcuterie.upload",
                description=type(self).__name__,
        ):
            storage = get_storage(self.storage_options)
            storage.save(file_name, BytesIO(resp.content))
            url = absolute_uri(storage.url(file_name))

        return url