def transform(self, item): """ :param item: """ try: attempt, pkg_analyzer, __, db_session = item except TypeError: # when a message is broken since the beginning in ways # it couldn't be processed by the SetupPipe, this # unpacking will fail as only an attempt instance is # referenced by `item`. attempt = item db_session = models.Session() logger.debug("%s started processing %s" % (self.__class__.__name__, item)) try: self._notifier(attempt, db_session).end() except RuntimeError: pass if "pkg_analyzer" in locals(): pkg_analyzer.restore_perms() if not attempt.is_valid: utils.mark_as_failed(attempt.filepath) try: transaction.commit() finally: db_session.close() logger.info("Finished validating %s" % attempt)
def mark_as_failed(self, silence=False): """ Mark primary path as failed. If the target file is gone, the error is logged and the exception is silenced. """ try: utils.mark_as_failed(self.primary_path) except OSError as e: logger.debug('The file is gone before marked as failed. %s' % e) if not silence: raise
def handle_events(self, job_queue): while True: filepath = job_queue.get() logger.debug('Started handling event for %s' % filepath) try: attempt = checkin.get_attempt(filepath) except ValueError as e: try: utils.mark_as_failed(filepath) except OSError as e: logger.debug('The file is gone before marked as failed. %s' % e) logger.debug('Failed during checkin: %s: %s' % (filepath, e)) except excepts.DuplicatedPackage as e: try: utils.mark_as_duplicated(filepath) except OSError as e: logger.debug('The file is gone before marked as duplicated. %s' % e) else: # Create a notification to keep track of the checkin process session = models.Session() checkin_notifier = self.CheckinNotifier(attempt, session) checkin_notifier.start() if attempt.is_valid: notification_msg = 'Attempt ready to be validated' notification_status = models.Status.ok else: notification_msg = 'Attempt cannot be validated' notification_status = models.Status.error checkin_notifier.tell(notification_msg, notification_status, 'Checkin') checkin_notifier.end() transaction.commit() #Send stream utils.send_message(self.stream, attempt, utils.make_digest) logging.debug('Message sent for %s: %s, %s' % (filepath, repr(attempt), repr(utils.make_digest)))
def get_attempt(package): """ Always returns a brand new models.Attempt instance, bound to the expected models.ArticlePkg instance. """ with PackageAnalyzer(package) as pkg: if pkg.is_valid_package(): article = models.get_or_create(models.ArticlePkg, **pkg.meta) pkg_checksum = utils.make_digest_file(package) attempt_meta = {'package_md5': pkg_checksum, 'articlepkg_id': article.id} attempt = models.get_or_create(models.Attempt, **attempt_meta) return attempt else: sys.stderr.write("Invalid package: %s\n" % pkg.errors) utils.mark_as_failed(package)
def transform(self, item): """ :param item: """ attempt, pkg_analyzer, __, db_session = item logger.debug('%s started processing %s' % (self.__class__.__name__, item)) try: self._notifier(attempt, db_session).end() except RuntimeError: pass if 'pkg_analyzer' in locals(): pkg_analyzer.restore_perms() if not attempt.is_valid: utils.mark_as_failed(attempt.filepath) attempt.end_validation() logger.info('Finished validating %s' % attempt)