本文整理汇总了Python中sentry.utils.cache.cache.set函数的典型用法代码示例。如果您正苦于以下问题:Python set函数的具体用法?Python set怎么用?Python set使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了set函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: get_send_to
def get_send_to(self, project=None):
"""
Returns a list of email addresses for the users that should be notified of alerts.
The logic for this is a bit complicated, but it does the following:
- Includes members if ``send_to_members`` is enabled **and** the user has not disabled alerts
for this project
The results of this call can be fairly expensive to calculate, so the send_to list gets cached
for 60 seconds.
"""
if project:
project_id = project.pk
else:
project_id = ""
conf_key = self.get_conf_key()
cache_key = "%s:send_to:%s" % (conf_key, project_id)
send_to_list = cache.get(cache_key)
if send_to_list is None:
send_to_list = set()
send_to_members = self.get_option("send_to_members", project)
if send_to_members and project and project.team:
member_set = self.get_sendable_users(project)
send_to_list |= set(self.get_emails_for_users(member_set))
send_to_list = filter(bool, send_to_list)
cache.set(cache_key, send_to_list, 60) # 1 minute cache
return send_to_list
开发者ID:sporting-news,项目名称:sentry,代码行数:31,代码来源:notify.py
示例2: fetch_release_file
def fetch_release_file(filename, release):
cache_key = "releasefile:%s:%s" % (release.id, md5(filename).hexdigest())
logger.debug("Checking cache for release artifact %r (release_id=%s)", filename, release.id)
result = cache.get(cache_key)
if result is None:
logger.debug("Checking database for release artifact %r (release_id=%s)", filename, release.id)
ident = ReleaseFile.get_ident(filename)
try:
releasefile = (
ReleaseFile.objects.filter(release=release, ident=ident).select_related("file", "file__blob").get()
)
except ReleaseFile.DoesNotExist:
logger.debug("Release artifact %r not found in database (release_id=%s)", filename, release.id)
cache.set(cache_key, -1, 60)
return None
logger.debug("Found release artifact %r (id=%s, release_id=%s)", filename, releasefile.id, release.id)
try:
with releasefile.file.getfile() as fp:
body = fp.read()
except Exception as e:
logger.exception(unicode(e))
result = -1
else:
result = (releasefile.file.headers, body, 200)
cache.set(cache_key, result, 3600)
if result == -1:
result = None
return result
开发者ID:simudream,项目名称:sentry,代码行数:31,代码来源:processor.py
示例3: get_rules
def get_rules(self):
cache_key = 'project:%d:rules' % (self.project.id,)
rules_list = cache.get(cache_key)
if rules_list is None:
rules_list = list(Rule.objects.filter(project=self.project))
cache.set(cache_key, rules_list, 60)
return rules_list
开发者ID:Akashguharoy,项目名称:sentry,代码行数:7,代码来源:processor.py
示例4: get_or_create
def get_or_create(cls, group, release, environment, datetime, **kwargs):
if not environment:
environment = ''
cache_key = cls.get_cache_key(group.id, release.id, environment)
instance = cache.get(cache_key)
if instance is None:
instance, created = cls.objects.get_or_create(
release_id=release.id,
group_id=group.id,
environment=environment,
defaults={
'project_id': group.project_id,
'first_seen': datetime,
'last_seen': datetime,
},
)
cache.set(cache_key, instance, 3600)
else:
created = False
# TODO(dcramer): this would be good to buffer
if not created:
instance.update(last_seen=datetime)
return instance
开发者ID:UNIVERSAL-IT-SYSTEMS,项目名称:sentry,代码行数:25,代码来源:grouprelease.py
示例5: fetch_release_file
def fetch_release_file(filename, release):
cache_key = 'release:%s:%s' % (
release.id,
hashlib.sha1(filename.encode('utf-8')).hexdigest(),
)
logger.debug('Checking cache for release artfiact %r (release_id=%s)',
filename, release.id)
result = cache.get(cache_key)
if result is None:
logger.debug('Checking database for release artifact %r (release_id=%s)',
filename, release.id)
ident = ReleaseFile.get_ident(filename)
try:
releasefile = ReleaseFile.objects.filter(
release=release,
ident=ident,
).select_related('file').get()
except ReleaseFile.DoesNotExist:
logger.debug('Release artifact %r not found in database (release_id=%s)',
filename, release.id)
return None
logger.debug('Found release artifact %r (id=%s, release_id=%s)',
filename, releasefile.id, release.id)
with releasefile.file.getfile() as fp:
body = fp.read()
result = (releasefile.file.headers, body, 200)
cache.set(cache_key, result, 60)
return result
开发者ID:aibar,项目名称:sentry,代码行数:30,代码来源:processor.py
示例6: chart
def chart(request, team=None, project=None):
gid = request.REQUEST.get('gid')
days = int(request.REQUEST.get('days', '90'))
if gid:
try:
group = Group.objects.get(pk=gid)
except Group.DoesNotExist:
return HttpResponseForbidden()
data = Group.objects.get_chart_data(group, max_days=days)
elif project:
data = Project.objects.get_chart_data(project, max_days=days)
elif team:
cache_key = 'api.chart:team=%s,days=%s' % (team.id, days)
data = cache.get(cache_key)
if data is None:
project_list = list(Project.objects.filter(team=team))
data = Project.objects.get_chart_data_for_group(project_list, max_days=days)
cache.set(cache_key, data, 300)
else:
cache_key = 'api.chart:user=%s,days=%s' % (request.user.id, days)
data = cache.get(cache_key)
if data is None:
project_list = Project.objects.get_for_user(request.user)
data = Project.objects.get_chart_data_for_group(project_list, max_days=days)
cache.set(cache_key, data, 300)
response = HttpResponse(json.dumps(data))
response['Content-Type'] = 'application/json'
return response
开发者ID:BlaShadow,项目名称:sentry,代码行数:32,代码来源:api.py
示例7: get_send_to
def get_send_to(self, project=None):
"""
Returns a list of email addresses for the users that should be notified of alerts.
The logic for this is a bit complicated, but it does the following:
The results of this call can be fairly expensive to calculate, so the send_to list gets cached
for 60 seconds.
"""
if project:
project_id = project.pk
else:
project_id = ''
if not (project and project.team):
return []
conf_key = self.get_conf_key()
cache_key = '%s:send_to:%s' % (conf_key, project_id)
send_to_list = cache.get(cache_key)
if send_to_list is None:
send_to_list = self.get_sendable_users(project)
send_to_list = filter(bool, send_to_list)
cache.set(cache_key, send_to_list, 60) # 1 minute cache
return send_to_list
开发者ID:noah-lee,项目名称:sentry,代码行数:28,代码来源:models.py
示例8: unset_value
def unset_value(self, instance, key):
self.filter(**{self.field_name: instance, 'key': key}).delete()
if instance.pk not in self.__metadata:
cache.delete(self._make_key(instance))
return
self.__metadata[instance.pk].pop(key, None)
cache.set(self._make_key(instance), self.__metadata[instance.pk])
开发者ID:Tug,项目名称:sentry,代码行数:7,代码来源:manager.py
示例9: get_or_create
def get_or_create(cls, release, project, environment, datetime, **kwargs):
cache_key = cls.get_cache_key(project.id, release.id, environment.id)
instance = cache.get(cache_key)
if instance is None:
instance, created = cls.objects.get_or_create(
release=release,
project=project,
environment=environment,
defaults={
'first_seen': datetime,
'last_seen': datetime,
}
)
cache.set(cache_key, instance, 3600)
else:
created = False
# Same as releaseenvironment model. Minimizes last_seen updates to once a minute
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:binlee1990,项目名称:sentry,代码行数:29,代码来源:releaseprojectenvironment.py
示例10: fetch_url
def fetch_url(url, logger=None):
"""
Pull down a URL, returning a UrlResult object.
Attempts to fetch from the cache.
"""
import sentry
cache_key = "fetch_url:%s" % url
result = cache.get(cache_key)
if result is not None:
return result
try:
opener = urllib2.build_opener()
opener.addheaders = [("User-Agent", "Sentry/%s" % sentry.VERSION)]
req = opener.open(url)
headers = dict(req.headers)
body = req.read().rstrip("\n")
except Exception:
if logger:
logger.error("Unable to fetch remote source for %r", url, exc_info=True)
return BAD_SOURCE
result = UrlResult(url, headers, body)
cache.set(cache_key, result, 60 * 5)
return result
开发者ID:hfeeki,项目名称:sentry,代码行数:29,代码来源:fetch_source.py
示例11: 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:
instance, created = cls.objects.get_or_create(
release_id=release.id,
organization_id=project.organization_id,
environment_id=environment.id,
defaults={
'first_seen': datetime,
'last_seen': datetime,
}
)
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:duanshuaimin,项目名称:sentry,代码行数:31,代码来源:releaseenvironment.py
示例12: fetch_url
def fetch_url(url, logger=None):
"""
Pull down a URL, returning a UrlResult object.
Attempts to fetch from the cache.
"""
import sentry
cache_key = 'fetch_url:v2:%s' % (hashlib.md5(url).hexdigest(),)
result = cache.get(cache_key)
if result is not None:
return UrlResult(*result)
try:
opener = urllib2.build_opener()
opener.addheaders = [('User-Agent', 'Sentry/%s' % sentry.VERSION)]
req = opener.open(url)
headers = dict(req.headers)
body = req.read()
if headers.get('content-encoding') == 'gzip':
# Content doesn't *have* to respect the Accept-Encoding header
# and may send gzipped data regardless.
# See: http://stackoverflow.com/questions/2423866/python-decompressing-gzip-chunk-by-chunk/2424549#2424549
body = zlib.decompress(body, 16 + zlib.MAX_WBITS)
body = body.rstrip('\n')
except Exception:
if logger:
logger.error('Unable to fetch remote source for %r', url, exc_info=True)
return BAD_SOURCE
result = (url, headers, body)
cache.set(cache_key, result, 60 * 5)
return UrlResult(url, headers, body)
开发者ID:Epictetus,项目名称:sentry-1,代码行数:35,代码来源:fetch_source.py
示例13: _get_project_enhancements_config
def _get_project_enhancements_config(project):
enhancements = project.get_option('sentry:grouping_enhancements')
enhancements_base = project.get_option('sentry:grouping_enhancements_base')
if not enhancements and not enhancements_base:
return DEFAULT_ENHANCEMENTS_CONFIG
if enhancements_base is None or enhancements_base not in ENHANCEMENT_BASES:
enhancements_base = DEFAULT_ENHANCEMENT_BASE
# Instead of parsing and dumping out config here, we can make a
# shortcut
from sentry.utils.cache import cache
from sentry.utils.hashlib import md5_text
cache_key = 'grouping-enhancements:' + \
md5_text('%s|%s' % (enhancements_base, enhancements)).hexdigest()
rv = cache.get(cache_key)
if rv is not None:
return rv
try:
rv = Enhancements.from_config_string(
enhancements or '', bases=[enhancements_base]).dumps()
except InvalidEnhancerConfig:
rv = DEFAULT_ENHANCEMENTS_CONFIG
cache.set(cache_key, rv)
return rv
开发者ID:getsentry,项目名称:sentry,代码行数:26,代码来源:api.py
示例14: __post_save
def __post_save(self, instance, **kwargs):
"""
Pushes changes to an instance into the cache, and removes invalid (changed)
lookup values.
"""
pk_name = instance._meta.pk.name
pk_names = ("pk", pk_name)
pk_val = instance.pk
for key in self.cache_fields:
if key in pk_names:
continue
# store pointers
cache.set(self.__get_lookup_cache_key(**{key: getattr(instance, key)}), pk_val, self.cache_ttl) # 1 hour
# Ensure we dont serialize the database into the cache
db = instance._state.db
instance._state.db = None
# store actual object
cache.set(self.__get_lookup_cache_key(**{pk_name: pk_val}), instance, self.cache_ttl)
instance._state.db = db
# Kill off any keys which are no longer valid
if instance in self.__cache:
for key in self.cache_fields:
if key not in self.__cache[instance]:
continue
value = self.__cache[instance][key]
if value != getattr(instance, key):
cache.delete(self.__get_lookup_cache_key(**{key: value}))
self.__cache_state(instance)
开发者ID:turleyhari,项目名称:sentry,代码行数:31,代码来源:manager.py
示例15: all_keys
def all_keys(self, project):
# TODO: cache invalidation via post_save/post_delete signals much like BaseManager
key = self._get_cache_key(project.id)
result = cache.get(key)
if result is None:
result = list(self.filter(project=project).values_list("key", flat=True))
cache.set(key, result, 60)
return result
开发者ID:turleyhari,项目名称:sentry,代码行数:8,代码来源:manager.py
示例16: _get_service_hooks
def _get_service_hooks(project_id):
from sentry.models import ServiceHook
cache_key = 'servicehooks:1:{}'.format(project_id)
result = cache.get(cache_key)
if result is None:
result = [(h.id, h.events) for h in
ServiceHook.objects.filter(project_id=project_id)]
cache.set(cache_key, result, 60)
return result
开发者ID:binlee1990,项目名称:sentry,代码行数:9,代码来源:post_process.py
示例17: reload_cache
def reload_cache(self, organization_id):
cache_key = self._make_key(organization_id)
result = dict(
(i.key, i.value)
for i in self.filter(organization=organization_id)
)
cache.set(cache_key, result)
self.__cache[organization_id] = result
return result
开发者ID:AyrtonRicardo,项目名称:sentry,代码行数:9,代码来源:organizationoption.py
示例18: _update_cachefiles
def _update_cachefiles(self, project, dsym_files):
rv = []
# Find all the known bad files we could not convert last time
# around
conversion_errors = {}
for dsym_file in dsym_files:
cache_key = 'scbe:%s:%s' % (dsym_file.uuid, dsym_file.file.checksum)
err = cache.get(cache_key)
if err is not None:
conversion_errors[dsym_file.uuid] = err
for dsym_file in dsym_files:
dsym_uuid = dsym_file.uuid
if dsym_uuid in conversion_errors:
continue
try:
with dsym_file.file.getfile(as_tempfile=True) as tf:
fo = FatObject.from_path(tf.name)
o = fo.get_object(uuid=dsym_file.uuid)
if o is None:
continue
symcache = o.make_symcache()
except SymbolicError as e:
cache.set('scbe:%s:%s' % (
dsym_uuid, dsym_file.file.checksum), e.message,
CONVERSION_ERROR_TTL)
conversion_errors[dsym_uuid] = e.message
logger.error('dsymfile.symcache-build-error',
exc_info=True, extra=dict(dsym_uuid=dsym_uuid))
continue
file = File.objects.create(
name=dsym_file.uuid,
type='project.symcache',
)
file.putfile(symcache.open_stream())
try:
with transaction.atomic():
rv.append((dsym_uuid, ProjectSymCacheFile.objects.get_or_create(
project=project,
cache_file=file,
dsym_file=dsym_file,
defaults=dict(
checksum=dsym_file.file.checksum,
version=symcache.file_format_version,
)
)[0]))
except IntegrityError:
file.delete()
rv.append((dsym_uuid, ProjectSymCacheFile.objects.get(
project=project,
dsym_file=dsym_file,
)))
return rv, conversion_errors
开发者ID:gencer,项目名称:sentry,代码行数:57,代码来源:dsymfile.py
示例19: reload_cache
def reload_cache(self, project_id):
cache_key = self._make_key(project_id)
result = dict(
(i.key, i.value)
for i in self.filter(project=project_id)
)
cache.set(cache_key, result)
self.__cache[project_id] = result
return result
开发者ID:PostPCEra,项目名称:sentry,代码行数:9,代码来源:projectoption.py
示例20: get_rules
def get_rules(project):
from sentry.models import Rule
cache_key = 'project:%d:rules' % (project.id,)
rules_list = cache.get(cache_key)
if rules_list is None:
rules_list = list(Rule.objects.filter(project=project))
cache.set(cache_key, rules_list, 60)
return rules_list
开发者ID:that0n3guy,项目名称:sentry,代码行数:9,代码来源:post_process.py
注:本文中的sentry.utils.cache.cache.set函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论