def main(): args = handle_args() logger = setup_logging(args.logfile_path) dburl = dbconfig.make_db_url(dbconfig.default_admin_db_params, args.dbname) if not db_utils.check_database_exists(dburl): raise RuntimeError("Database not found") if six.PY3: stdin = sys.stdin.buffer.read() else: stdin = sys.stdin.read() # Py2 v = voeventparse.loads(stdin) session = Session(bind=create_engine(dburl)) try: conv.safe_insert_voevent(session, v) session.commit() except: logger.exception( "Could not insert packet with ivorn {} into {}".format( v.attrib['ivorn'], args.dbname)) logger.info("Loaded packet with ivorn {} into {}".format( v.attrib['ivorn'], args.dbname)) return 0
def test_safe_insert(self, fixture_db_session, simple_populated_db, caplog): s = fixture_db_session dbinf = simple_populated_db nlogs = len(caplog.records) with caplog.at_level(logging.WARNING): safe_insert_voevent(s, dbinf.insert_packets[0]) assert len(caplog.records) == nlogs + 1 assert caplog.records[-1].levelname == 'WARNING' bad_packet = copy.copy(dbinf.insert_packets[0]) bad_packet.Who.AuthorIVORN = 'ivo://foo.bar' with pytest.raises(ValueError): safe_insert_voevent(s, bad_packet)
def test_safe_insert(self, fixture_db_session, simple_populated_db, caplog ): s = fixture_db_session dbinf = simple_populated_db nlogs = len(caplog.records()) with caplog.atLevel(logging.WARNING): safe_insert_voevent(s, dbinf.insert_packets[0]) assert len(caplog.records()) == nlogs + 1 assert caplog.records()[-1].levelname == 'WARNING' bad_packet = copy.copy(dbinf.insert_packets[0]) bad_packet.Who.AuthorIVORN = 'ivo://foo.bar' with pytest.raises(ValueError): safe_insert_voevent(s, bad_packet)
def __call__(self, event): """ Add an event to the celery processing queue """ log.debug("Passing to voeventdb: %s" % (event.attrib['ivorn'],)) session = Session(bind=dbengine) try: v = voeventparse.loads(event.text) dbconv.safe_insert_voevent(session, v) session.commit() except Exception as e: log.warn("Could not insert packet with ivorn {} into database {}".format( v.attrib['ivorn'], voeventdb_dbname)) self.deferred.errback(e) log.info("Loaded {} into database {}".format( v.attrib['ivorn'], voeventdb_dbname))
def __call__(self, event): """ Add an event to the celery processing queue """ v = None try: session = Session(bind=dbengine) v = voeventparse.loads(event.raw_bytes) dbconv.safe_insert_voevent(session, v) session.commit() except Exception as e: if v is None: log.warn("Could not parse event-bytes as voevent") else: log.warn( "Could not insert packet with ivorn {} into database {}". format(v.attrib['ivorn'], voeventdb_dbname)) self.deferred.errback(e) log.info("Loaded {} into database {}".format(v.attrib['ivorn'], voeventdb_dbname))
def main(): args = handle_args() logger = setup_logging(args.logfile_path) dburl = dbconfig.make_db_url(dbconfig.default_admin_db_params, args.dbname) if not db_utils.check_database_exists(dburl): raise RuntimeError("Database not found") stdin = sys.stdin.read() v = voeventparse.loads(stdin) session = Session(bind=create_engine(dburl)) try: conv.safe_insert_voevent(session, v) session.commit() except: logger.exception("Could not insert packet with ivorn {} into {}".format( v.attrib['ivorn'], args.dbname)) logger.info("Loaded packet with ivorn {} into {}".format( v.attrib['ivorn'], args.dbname)) return 0
def ingest_voevent_celerytask(bytestring): """ Ingest the voevent into a local instance of voeventdb. """ v = voeventparse.loads(bytestring) logger.debug("Load for ingest: " + v.attrib['ivorn']) session = Session(bind=dbengine) try: dbconv.safe_insert_voevent(session, v) session.commit() except: if (v.attrib['role'] == voeventparse.definitions.roles.test and v.attrib['ivorn'].startswith('ivo://nasa.gsfc.gcn/INTEGRAL')): logger.warning( "Ignoring mismatched duplicate-ivorn test events from " "NASA-INTEGRAL stream") else: logger.exception( "Could not insert packet with ivorn {} into {}".format( v.attrib['ivorn'], voeventdb_dbname)) logger.info("Ingested:" + v.attrib['ivorn'])