def reprocess_events(project_id, **kwargs): from sentry.models import ProcessingIssue from sentry.coreapi import insert_data_to_database_legacy from sentry import app lock_key = "events:reprocess_events:%s" % project_id have_more = False lock = app.locks.get(lock_key, duration=60) try: with lock.acquire(): raw_events, have_more = ProcessingIssue.objects.find_resolved( project_id) if raw_events: for raw_event in raw_events: insert_data_to_database_legacy(raw_event.data.data, from_reprocessing=True) create_reprocessing_report(project_id=project_id, event_id=raw_event.event_id) # Here we only delete the raw event but leave the # reprocessing report alive. When the queue # eventually kicks in this should clean up. raw_event.delete() except UnableToAcquireLock as error: logger.warning("reprocess_events.fail", extra={"error": error}) # There are more, kick us off again if have_more: reprocess_events.delay(project_id=project_id)
def mark_failed(self, last_checkin=None, reason=MonitorFailure.UNKNOWN): from sentry.coreapi import insert_data_to_database_legacy from sentry.event_manager import EventManager from sentry.models import Project from sentry.signals import monitor_failed if last_checkin is None: next_checkin_base = timezone.now() last_checkin = self.last_checkin or timezone.now() else: next_checkin_base = last_checkin affected = (type(self).objects.filter( Q(last_checkin__lte=last_checkin) | Q(last_checkin__isnull=True), id=self.id).update( next_checkin=self.get_next_scheduled_checkin( next_checkin_base), status=MonitorStatus.ERROR, last_checkin=last_checkin, )) if not affected: return False event_manager = EventManager( { "logentry": { "message": "Monitor failure: %s (%s)" % (self.name, reason) }, "contexts": { "monitor": get_monitor_context(self) }, "fingerprint": ["monitor", six.text_type(self.guid), reason], }, project=Project(id=self.project_id), ) event_manager.normalize() data = event_manager.get_data() insert_data_to_database_legacy(data) monitor_failed.send(monitor=self, sender=type(self)) return True