def delete_galaxy(connection, galaxy_ids): for galaxy_id in galaxy_ids: transaction = connection.begin() galaxy = connection.execute(select([GALAXY]).where(GALAXY.c.galaxy_id == galaxy_id)).first() if galaxy is None: LOG.info('Error: Galaxy with galaxy_id of %d was not found', galaxy_id) else: LOG.info('Deleting Galaxy with galaxy_id of %d - %s', galaxy_id, galaxy[GALAXY.c.name]) area_count = connection.execute(select([func.count(AREA.c.area_id)]).where(AREA.c.galaxy_id == galaxy[GALAXY.c.galaxy_id])).first()[0] counter = 1 for area_id1 in connection.execute(select([AREA.c.area_id]).where(AREA.c.galaxy_id == galaxy[GALAXY.c.galaxy_id]).order_by(AREA.c.area_id)): LOG.info("Deleting galaxy {0} area {1}. {2} of {3}".format(galaxy_id, area_id1[0], counter, area_count)) connection.execute(PIXEL_RESULT.delete().where(PIXEL_RESULT.c.area_id == area_id1[0])) # Give the rest of the world a chance to access the database time.sleep(0.1) counter += 1 if shutdown() is True: transaction.rollback() raise SystemExit LOG.info("Deleting FITS headers for galaxy {0}".format(galaxy_id)) connection.execute(FITS_HEADER.delete().where(FITS_HEADER.c.galaxy_id == galaxy[GALAXY.c.galaxy_id])) # Now empty the bucket of the sed files s3helper = S3Helper() bucket = s3helper.get_bucket(get_sed_files_bucket()) galaxy_file_name = get_galaxy_file_name(galaxy[GALAXY.c.name], galaxy[GALAXY.c.run_id], galaxy[GALAXY.c.galaxy_id]) for key in bucket.list(prefix='{0}/'.format(galaxy_file_name)): # Ignore the key if key.key.endswith('/'): continue bucket.delete_key(key) if shutdown() is True: transaction.rollback() raise SystemExit # Now the folder key = Key(bucket) key.key = '{0}/'.format(galaxy_file_name) bucket.delete_key(key) LOG.info('Galaxy with galaxy_id of %d was deleted', galaxy_id) connection.execute(GALAXY.update().where(GALAXY.c.galaxy_id == galaxy_id).values(status_id=DELETED, status_time=datetime.datetime.now())) if shutdown() is True: transaction.rollback() raise SystemExit transaction.commit()
def delete_galaxy(connection, galaxy_ids): for galaxy_id in galaxy_ids: transaction = connection.begin() galaxy = connection.execute( select([GALAXY]).where(GALAXY.c.galaxy_id == galaxy_id)).first() if galaxy is None: LOG.info('Error: Galaxy with galaxy_id of %d was not found', galaxy_id) else: LOG.info('Deleting Galaxy with galaxy_id of %d - %s', galaxy_id, galaxy[GALAXY.c.name]) area_count = connection.execute( select([func.count(AREA.c.area_id)]).where( AREA.c.galaxy_id == galaxy[GALAXY.c.galaxy_id])).first()[0] counter = 1 for area_id1 in connection.execute( select([AREA.c.area_id]).where(AREA.c.galaxy_id == galaxy[ GALAXY.c.galaxy_id]).order_by(AREA.c.area_id)): LOG.info("Deleting galaxy {0} area {1}. {2} of {3}".format( galaxy_id, area_id1[0], counter, area_count)) connection.execute(PIXEL_RESULT.delete().where( PIXEL_RESULT.c.area_id == area_id1[0])) # Give the rest of the world a chance to access the database time.sleep(0.1) counter += 1 if shutdown() is True: transaction.rollback() raise SystemExit LOG.info("Deleting FITS headers for galaxy {0}".format(galaxy_id)) connection.execute(FITS_HEADER.delete().where( FITS_HEADER.c.galaxy_id == galaxy[GALAXY.c.galaxy_id])) # Now empty the bucket of the sed files s3helper = S3Helper() bucket = s3helper.get_bucket(get_sed_files_bucket()) galaxy_file_name = get_galaxy_file_name(galaxy[GALAXY.c.name], galaxy[GALAXY.c.run_id], galaxy[GALAXY.c.galaxy_id]) for key in bucket.list(prefix='{0}/'.format(galaxy_file_name)): # Ignore the key if key.key.endswith('/'): continue bucket.delete_key(key) if shutdown() is True: transaction.rollback() raise SystemExit # Now the folder key = Key(bucket) key.key = '{0}/'.format(galaxy_file_name) bucket.delete_key(key) LOG.info('Galaxy with galaxy_id of %d was deleted', galaxy_id) connection.execute( GALAXY.update().where(GALAXY.c.galaxy_id == galaxy_id).values( status_id=DELETED, status_time=datetime.datetime.now())) if shutdown() is True: transaction.rollback() raise SystemExit transaction.commit()
def assimilate_handler(self, wu, results, canonical_result): """ Process the Results. """ self.logDebug("Start of assimilate_handler for wu %d\n", wu.id) connection = None try: if wu.canonical_result: out_file = self.get_file_path(canonical_result) self.area = None if out_file: if os.path.isfile(out_file): pass else: self.logDebug("File [%s] not found\n", out_file) out_file = None if out_file: self.logDebug("Reading File [%s]\n", out_file) start = time.time() connection = ENGINE.connect() result_count = self._process_result(connection, out_file, wu) if self.noinsert: pass else: if not result_count: self.logCritical("No results were found in the output file\n") if self._area_id is None: self.logDebug("The Area was not found\n") else: self._database_queue.append(AREA.update() .where(AREA.c.area_id == self._area_id) .values(workunit_id=wu.id, update_time=datetime.datetime.now())) user_id_set = set() for result in results: if result.user and result.validate_state == boinc_db.VALIDATE_STATE_VALID: user_id = result.user.id if user_id not in user_id_set: user_id_set.add(user_id) self._database_queue.append(AREA_USER.delete().where(AREA_USER.c.area_id == self._area_id)) insert_area_user = AREA_USER.insert() insert_galaxy_user = GALAXY_USER.insert().prefix_with('IGNORE') for user_id in user_id_set: self._database_queue.append(insert_area_user.values(area_id=self._area_id, userid=user_id)) self._database_queue.append(insert_galaxy_user.values(galaxy_id=self._galaxy_id, userid=user_id)) # Copy the file to S3 s3helper = S3Helper() s3helper.add_file_to_bucket(get_sed_files_bucket(), get_key_sed(self._galaxy_name, self._run_id, self._galaxy_id, self._area_id), out_file, reduced_redundancy=True) time_taken = '{0:.2f}'.format(time.time() - start) self.logDebug("Saving %d results for workunit %d in %s seconds\n", result_count, wu.id, time_taken) self._run_pending_db_tasks(connection) connection.close() else: self.logCritical("The output file was not found\n") else: self.logDebug("No canonical_result for workunit\n") self.report_errors(wu) except: if connection is not None: connection.close() print "Unexpected error:", sys.exc_info()[0] traceback.print_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2]) self.logCritical("Unexpected error occurred, retrying...\n") return -1 return 0