• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python locks.get函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sentry.app.locks.get函数的典型用法代码示例。如果您正苦于以下问题:Python get函数的具体用法?Python get怎么用?Python get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: _finish_login_pipeline

    def _finish_login_pipeline(self, identity):
        """
        The login flow executes both with anonymous and authenticated users.

        Upon completion a few branches exist:

        If the identity is already linked, the user should be logged in
        and redirected immediately.

        Otherwise, the user is presented with a confirmation window. That window
        will show them the new account that will be created, and if they're
        already authenticated an optional button to associate the identity with
        their account.
        """
        auth_provider = self.auth_provider
        user_id = identity['id']

        lock = locks.get(
            'sso:auth:{}:{}'.format(
                auth_provider.id,
                md5_text(user_id).hexdigest(),
            ),
            duration=5,
        )
        with TimedRetryPolicy(5)(lock.acquire):
            try:
                auth_identity = AuthIdentity.objects.select_related('user').get(
                    auth_provider=auth_provider,
                    ident=user_id,
                )
            except AuthIdentity.DoesNotExist:
                auth_identity = None

            # Handle migration of identity keys
            if not auth_identity and isinstance(user_id, MigratingIdentityId):
                try:
                    auth_identity = AuthIdentity.objects.select_related('user').get(
                        auth_provider=auth_provider,
                        ident=user_id.legacy_id,
                    )
                    auth_identity.update(ident=user_id.id)
                except AuthIdentity.DoesNotExist:
                    auth_identity = None

            if not auth_identity:
                return self._handle_unknown_identity(identity)

            # If the User attached to this AuthIdentity is not active,
            # we want to clobber the old account and take it over, rather than
            # getting logged into the inactive account.
            if not auth_identity.user.is_active:

                # Current user is also not logged in, so we have to
                # assume unknown.
                if not self.request.user.is_authenticated():
                    return self._handle_unknown_identity(identity)

                auth_identity = self._handle_attach_identity(identity)

            return self._handle_existing_identity(auth_identity, identity)
开发者ID:hosmelq,项目名称:sentry,代码行数:60,代码来源:helper.py


示例2: _ensure_blob

    def _ensure_blob(self, orm, file):
        from sentry.app import locks
        from sentry.utils.retries import TimedRetryPolicy

        File = orm['sentry.File']
        FileBlob = orm['sentry.FileBlob']

        lock = locks.get('fileblob:convert:{}'.format(file.checksum), duration=60)
        with TimedRetryPolicy(60 * 5)(lock.acquire):
            if not file.storage:
                return

            try:
                blob = FileBlob.objects.get(checksum=file.checksum)
            except FileBlob.DoesNotExist:
                blob = FileBlob.objects.create(
                    checksum=file.checksum,
                    storage=file.storage,
                    storage_options=file.storage_options,
                    path=file.path,
                    size=file.size,
                    timestamp=file.timestamp,
                )

            File.objects.filter(
                id=file.id,
            ).update(blob=blob)
            file.blob = blob
开发者ID:Akashguharoy,项目名称:sentry,代码行数:28,代码来源:0213_migrate_file_blobs.py


示例3: _finish_login_pipeline

    def _finish_login_pipeline(self, identity):
        """
        The login flow executes both with anonymous and authenticated users.

        Upon completion a few branches exist:

        If the identity is already linked, the user should be logged in
        and redirected immediately.

        Otherwise, the user is presented with a confirmation window. That window
        will show them the new account that will be created, and if they're
        already authenticated an optional button to associate the identity with
        their account.
        """
        auth_provider = self.auth_provider
        lock = locks.get(
            'sso:auth:{}:{}'.format(
                auth_provider.id,
                md5(unicode(identity['id'])).hexdigest(),
            ),
            duration=5,
        )
        with TimedRetryPolicy(5)(lock.acquire):
            try:
                auth_identity = AuthIdentity.objects.get(
                    auth_provider=auth_provider,
                    ident=identity['id'],
                )
            except AuthIdentity.DoesNotExist:
                return self._handle_unknown_identity(identity)
            return self._handle_existing_identity(auth_identity, identity)
开发者ID:zhangmuxi,项目名称:sentry,代码行数:31,代码来源:helper.py


示例4: start_release

    def start_release(self, version, **values):
        values.setdefault('date_started', timezone.now())

        affected = Release.objects.filter(
            version=version,
            organization_id=self.project.organization_id,
            projects=self.project,
        ).update(**values)
        if not affected:
            release = Release.objects.filter(
                version=version,
                organization_id=self.project.organization_id,
            ).first()
            if release:
                release.update(**values)
            else:
                lock_key = Release.get_lock_key(self.project.organization_id, version)
                lock = locks.get(lock_key, duration=5)
                with TimedRetryPolicy(10)(lock.acquire):
                    try:
                        release = Release.objects.get(
                            version=version,
                            organization_id=self.project.organization_id
                        )
                    except Release.DoesNotExist:
                        release = Release.objects.create(
                            version=version,
                            organization_id=self.project.organization_id,
                            **values
                        )

            release.add_project(self.project)
开发者ID:faulkner,项目名称:sentry,代码行数:32,代码来源:releasehook.py


示例5: get_security_token

 def get_security_token(self):
     lock = locks.get(self.get_lock_key(), duration=5)
     with TimedRetryPolicy(10)(lock.acquire):
         security_token = self.get_option('sentry:token', None)
         if security_token is None:
             security_token = uuid1().hex
             self.update_option('sentry:token', security_token)
         return security_token
开发者ID:binlee1990,项目名称:sentry,代码行数:8,代码来源:project.py


示例6: save

 def save(self, *args, **kwargs):
     if not self.slug:
         lock = locks.get('slug:organization', duration=5)
         with TimedRetryPolicy(10)(lock.acquire):
             slugify_instance(self, self.name, reserved=RESERVED_ORGANIZATION_SLUGS)
         super(Organization, self).save(*args, **kwargs)
     else:
         super(Organization, self).save(*args, **kwargs)
开发者ID:NuttasitBoonwat,项目名称:sentry,代码行数:8,代码来源:organization.py


示例7: save

 def save(self, *args, **kwargs):
     if not self.slug:
         lock = locks.get('slug:project', duration=5)
         with TimedRetryPolicy(10)(lock.acquire):
             slugify_instance(self, self.name, organization=self.organization)
         super(Project, self).save(*args, **kwargs)
     else:
         super(Project, self).save(*args, **kwargs)
开发者ID:ForkRepo,项目名称:sentry,代码行数:8,代码来源:project.py


示例8: delete_file

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)
开发者ID:Kayle009,项目名称:sentry,代码行数:9,代码来源:files.py


示例9: notify_if_ready

    def notify_if_ready(cls, deploy_id, fetch_complete=False):
        """
        create activity and send deploy notifications
        if they haven't been sent
        """
        from sentry.models import Activity, Environment, ReleaseCommit, ReleaseHeadCommit

        lock_key = cls.get_lock_key(deploy_id)
        lock = locks.get(lock_key, duration=30)
        with TimedRetryPolicy(10)(lock.acquire):
            deploy = cls.objects.filter(
                id=deploy_id,
            ).select_related('release').get()
            if deploy.notified:
                return

            release = deploy.release
            environment = Environment.objects.get(
                organization_id=deploy.organization_id,
                id=deploy.environment_id,
            )

            if not fetch_complete:
                release_has_commits = ReleaseCommit.objects.filter(
                    organization_id=release.organization_id,
                    release=release,
                ).exists()

                if not release_has_commits:
                    # check if we have head commits, which
                    # would indicate that we're waiting for
                    # fetch_commits to complete
                    if ReleaseHeadCommit.objects.filter(
                        organization_id=release.organization_id,
                        release=release,
                    ).exists():
                        return

            activity = None
            for project in deploy.release.projects.all():
                activity = Activity.objects.create(
                    type=Activity.DEPLOY,
                    project=project,
                    ident=release.version,
                    data={
                        'version': release.version,
                        'deploy_id': deploy.id,
                        'environment': environment.name,
                    },
                    datetime=deploy.date_finished,
                )
            # Somewhat hacky, only send notification for one
            # Deploy Activity record because it will cover all projects
            if activity is not None:
                activity.send_notification()
                deploy.update(notified=True)
开发者ID:Kayle009,项目名称:sentry,代码行数:56,代码来源:deploy.py


示例10: get_or_create

    def get_or_create(cls, project, release, environment, datetime, **kwargs):
        cache_key = cls.get_cache_key(project.id, release.id, environment.id)

        instance = cache.get(cache_key)
        if instance is None:
            release_envs = list(cls.objects.filter(
                release_id=release.id,
                organization_id=project.organization_id,
                environment_id=environment.id,
            ))
            if release_envs:
                instance = release_envs[0]
                for re in release_envs:
                    if re.project_id == project.id:
                        instance = re
                created = False
            else:
                lock_key = cls.get_lock_key(project.organization_id, release.id, environment.id)
                lock = locks.get(lock_key, duration=5)
                with TimedRetryPolicy(10)(lock.acquire):
                    try:
                        instance, created = cls.objects.get(
                            release_id=release.id,
                            organization_id=project.organization_id,
                            environment_id=environment.id,
                        ), False
                    except cls.DoesNotExist:
                        instance, created = cls.objects.create(
                            release_id=release.id,
                            project_id=project.id,
                            organization_id=project.organization_id,
                            environment_id=environment.id,
                            first_seen=datetime,
                            last_seen=datetime,
                        ), True
            cache.set(cache_key, instance, 3600)
        else:
            created = False

        # TODO(dcramer): this would be good to buffer, but until then we minimize
        # updates to once a minute, and allow Postgres to optimistically skip
        # it even if we can't
        if not created and instance.last_seen < datetime - timedelta(seconds=60):
            cls.objects.filter(
                id=instance.id,
                last_seen__lt=datetime - timedelta(seconds=60),
            ).update(
                last_seen=datetime,
            )
            instance.last_seen = datetime
            cache.set(cache_key, instance, 3600)
        return instance
开发者ID:sashahilton00,项目名称:sentry,代码行数:52,代码来源:releaseenvironment.py


示例11: process_pending

def process_pending():
    """
    Process pending buffers.
    """
    from sentry import buffer
    from sentry.app import locks

    lock = locks.get('buffer:process_pending', duration=60)
    try:
        with lock.acquire():
            buffer.process_pending()
    except UnableToAcquireLock as error:
        logger.warning('process_pending.fail', extra={'error': error})
开发者ID:duanshuaimin,项目名称:sentry,代码行数:13,代码来源:process_buffer.py


示例12: save

 def save(self, *args, **kwargs):
     if not self.slug:
         lock = locks.get('slug:project', duration=5)
         with TimedRetryPolicy(10)(lock.acquire):
             slugify_instance(
                 self,
                 self.name,
                 organization=self.organization,
                 reserved=RESERVED_PROJECT_SLUGS)
         super(Project, self).save(*args, **kwargs)
     else:
         super(Project, self).save(*args, **kwargs)
     self.update_rev_for_option()
开发者ID:binlee1990,项目名称:sentry,代码行数:13,代码来源:project.py


示例13: upgrade

def upgrade(ctx, verbosity, traceback, noinput, lock, no_repair):
    "Perform any pending database migrations and upgrades."

    if lock:
        from sentry.app import locks
        from sentry.utils.locking import UnableToAcquireLock
        lock = locks.get('upgrade', duration=0)
        try:
            with lock.acquire():
                _upgrade(not noinput, traceback, verbosity, not no_repair)
        except UnableToAcquireLock:
            raise click.ClickException('Unable to acquire `upgrade` lock.')
    else:
        _upgrade(not noinput, traceback, verbosity, not no_repair)
开发者ID:bsergean,项目名称:sentry,代码行数:14,代码来源:upgrade.py


示例14: enqueue_scheduled_jobs

def enqueue_scheduled_jobs(**kwargs):
    from sentry.celery import app

    with locks.get('scheduler.process', duration=60).acquire():
        job_list = list(ScheduledJob.objects.filter(
            date_scheduled__lte=timezone.now(),
        )[:101])

        if len(job_list) > 100:
            logger.debug('More than 100 ScheduledJobs found.')

        for job in job_list:
            logger.debug('Sending scheduled job %s with payload %r', job.name, job.payload)
            app.send_task(job.name, kwargs=job.payload)
            job.delete()
开发者ID:Kayle009,项目名称:sentry,代码行数:15,代码来源:scheduler.py


示例15: get_webhook_secret

 def get_webhook_secret(self, organization):
     lock = locks.get('bitbucket:webhook-secret:{}'.format(organization.id), duration=60)
     with lock.acquire():
         secret = OrganizationOption.objects.get_value(
             organization=organization,
             key='bitbucket:webhook_secret',
         )
         if secret is None:
             secret = uuid4().hex + uuid4().hex
             OrganizationOption.objects.set_value(
                 organization=organization,
                 key='bitbucket:webhook_secret',
                 value=secret,
             )
     return secret
开发者ID:getsentry,项目名称:sentry-plugins,代码行数:15,代码来源:repository_provider.py


示例16: get_webhook_secret

 def get_webhook_secret(self, organization):
     # TODO(LB): Revisit whether Integrations V3 should be using OrganizationOption for storage
     lock = locks.get(u'bitbucket:webhook-secret:{}'.format(organization.id), duration=60)
     with lock.acquire():
         secret = OrganizationOption.objects.get_value(
             organization=organization,
             key='bitbucket:webhook_secret',
         )
         if secret is None:
             secret = generate_token()
             OrganizationOption.objects.set_value(
                 organization=organization,
                 key='bitbucket:webhook_secret',
                 value=secret,
             )
     return secret
开发者ID:Kayle009,项目名称:sentry,代码行数:16,代码来源:repository.py


示例17: process_pending

def process_pending(partition=None):
    """
    Process pending buffers.
    """
    from sentry import buffer
    from sentry.app import locks

    if partition is None:
        lock_key = 'buffer:process_pending'
    else:
        lock_key = 'buffer:process_pending:%d' % partition

    lock = locks.get(lock_key, duration=60)

    try:
        with lock.acquire():
            buffer.process_pending(partition=partition)
    except UnableToAcquireLock as error:
        logger.warning('process_pending.fail', extra={'error': error, 'partition': partition})
开发者ID:Kayle009,项目名称:sentry,代码行数:19,代码来源:process_buffer.py


示例18: from_file

    def from_file(cls, fileobj):
        """
        Retrieve a list of FileBlobIndex instances for the given file.

        If not already present, this will cause it to be stored.

        >>> blobs = FileBlob.from_file(fileobj)
        """
        size = 0

        checksum = sha1(b'')
        for chunk in fileobj:
            size += len(chunk)
            checksum.update(chunk)
        checksum = checksum.hexdigest()

        # TODO(dcramer): the database here is safe, but if this lock expires
        # and duplicate files are uploaded then we need to prune one
        lock = locks.get(u'fileblob:upload:{}'.format(checksum), duration=60 * 10)
        with TimedRetryPolicy(60)(lock.acquire):
            # test for presence
            try:
                existing = FileBlob.objects.get(checksum=checksum)
            except FileBlob.DoesNotExist:
                pass
            else:
                return existing

            blob = cls(
                size=size,
                checksum=checksum,
            )

            blob.path = cls.generate_unique_path(blob.timestamp)

            storage = get_storage()
            storage.save(blob.path, fileobj)
            blob.save()

        metrics.timing('filestore.blob-size', size)
        return blob
开发者ID:alexandrul,项目名称:sentry,代码行数:41,代码来源:file.py


示例19: finish_release

    def finish_release(self, version, **values):
        values.setdefault('date_released', timezone.now())
        affected = Release.objects.filter(
            version=version,
            organization_id=self.project.organization_id,
            projects=self.project,
        ).update(**values)
        if not affected:
            release = Release.objects.filter(
                version=version,
                organization_id=self.project.organization_id,
            ).first()
            if release:
                release.update(**values)
            else:
                lock_key = Release.get_lock_key(self.project.organization_id, version)
                lock = locks.get(lock_key, duration=5)
                with TimedRetryPolicy(10)(lock.acquire):
                    try:
                        release = Release.objects.get(
                            version=version,
                            organization_id=self.project.organization_id,
                        )
                    except Release.DoesNotExist:
                        release = Release.objects.create(
                            version=version,
                            organization_id=self.project.organization_id,
                            **values
                        )
            release.add_project(self.project)

        activity = Activity.objects.create(
            type=Activity.RELEASE,
            project=self.project,
            ident=version,
            data={'version': version},
            datetime=values['date_released'],
        )
        activity.send_notification()
开发者ID:faulkner,项目名称:sentry,代码行数:39,代码来源:releasehook.py


示例20: get_or_create

    def get_or_create(cls, project, name):
        name = name or ''

        cache_key = cls.get_cache_key(project.id, name)

        env = cache.get(cache_key)
        if env is None:
            try:
                env = cls.objects.get(
                    projects=project,
                    organization_id=project.organization_id,
                    name=name,
                )
            except cls.DoesNotExist:
                env = cls.objects.filter(
                    organization_id=project.organization_id,
                    name=name,
                ).order_by('date_added').first()
                if not env:
                    lock_key = cls.get_lock_key(project.organization_id, name)
                    lock = locks.get(lock_key, duration=5)
                    with TimedRetryPolicy(10)(lock.acquire):
                        try:
                            env = cls.objects.get(
                                organization_id=project.organization_id,
                                name=name,
                            )
                        except cls.DoesNotExist:
                            env = cls.objects.create(
                                project_id=project.id,
                                name=name,
                                organization_id=project.organization_id
                            )
                env.add_project(project)

            cache.set(cache_key, env, 3600)

        return env
开发者ID:sashahilton00,项目名称:sentry,代码行数:38,代码来源:environment.py



注:本文中的sentry.app.locks.get函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python ratelimiter.is_limited函数代码示例发布时间:2022-05-27
下一篇:
Python buffer.incr函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap