Ejemplo n.º 1
0
def inner_refresh_all_builds() -> None:
    """Refreshes all AppStoreConnect builds for all projects.

    This iterates over all the projects configured in Sentry and for any which has an
    AppStoreConnect symbol source configured will poll the AppStoreConnect API to check if
    there are new builds.
    """
    # We have no way to query for AppStore Connect symbol sources directly, but
    # getting all of the project options that have custom symbol sources
    # configured is a reasonable compromise, as the number of those should be
    # low enough to traverse every hour.
    # Another alternative would be to get a list of projects that have had a
    # previous successful import, as indicated by existing `AppConnectBuild`
    # objects. But that would miss projects that have a valid AppStore Connect
    # setup, but have not yet published any kind of build to AppStore.
    options = ProjectOption.objects.filter(
        key=appconnect.SYMBOL_SOURCES_PROP_NAME)
    count = 0
    for option in options:
        with sdk.push_scope() as scope:
            scope.set_tag("project", option.project_id)
            try:
                if not option.value:
                    # An empty string set as option value, the UI does this when deleting
                    # all sources.  This is not valid JSON.
                    continue
                # We are parsing JSON thus all types are Any, so give the type-checker some
                # extra help.  We are maybe slightly lying about the type, but the
                # attributes we do access are all string values.
                all_sources: List[Mapping[str, str]] = json.loads(option.value)
                for source in all_sources:
                    try:
                        source_id = source["id"]
                        source_type = source["type"]
                    except KeyError:
                        logger.exception("Malformed symbol source")
                        continue
                    if source_type == appconnect.SYMBOL_SOURCE_TYPE_NAME:
                        dsym_download.apply_async(
                            kwargs={
                                "project_id": option.project_id,
                                "config_id": source_id,
                            })
                        count += 1
            except Exception:
                logger.exception("Failed to refresh AppStoreConnect builds")
    metrics.gauge("tasks.app_store_connect.refreshed", count, sample_rate=1)
Ejemplo n.º 2
0
        def _wrapped(*args, **kwargs):
            # TODO(dcramer): we want to tag a transaction ID, but overriding
            # the base on app.task seems to cause problems w/ Celery internals
            transaction_id = kwargs.pop('__transaction_id', None)

            key = 'jobs.duration'
            if stat_suffix:
                instance = u'{}.{}'.format(name, stat_suffix(*args, **kwargs))
            else:
                instance = name

            with push_scope() as scope:
                scope.set_tag('task_name', name)
                scope.set_tag('transaction_id', transaction_id)

                with metrics.timer(key, instance=instance), \
                        track_memory_usage('jobs.memory_change', instance=instance):
                    result = func(*args, **kwargs)
            return result