def test_filesystem_event_log_storage_run_corrupted_bad_data( self, storage): SqlEventLogStorageMetadata.create_all( create_engine(storage.conn_string_for_shard("foo"))) with storage.run_connection("foo") as conn: event_insert = ( SqlEventLogStorageTable.insert().values( # pylint: disable=no-value-for-parameter run_id="foo", event="{bar}", dagster_event_type=None, timestamp=None)) conn.execute(event_insert) with pytest.raises(DagsterEventLogInvalidForRun): storage.get_logs_for_run("foo") SqlEventLogStorageMetadata.create_all( create_engine(storage.conn_string_for_shard("bar"))) with storage.run_connection("bar") as conn: event_insert = ( SqlEventLogStorageTable.insert().values( # pylint: disable=no-value-for-parameter run_id="bar", event="3", dagster_event_type=None, timestamp=None)) conn.execute(event_insert) with pytest.raises(DagsterEventLogInvalidForRun): storage.get_logs_for_run("bar")
def test_filesystem_event_log_storage_run_corrupted_bad_data(): with seven.TemporaryDirectory() as tmpdir_path: storage = SqliteEventLogStorage(tmpdir_path) SqlEventLogStorageMetadata.create_all( create_engine(storage.conn_string_for_run_id('foo'))) with storage.connect('foo') as conn: event_insert = SqlEventLogStorageTable.insert().values( # pylint: disable=no-value-for-parameter run_id='foo', event='{bar}', dagster_event_type=None, timestamp=None) conn.execute(event_insert) with pytest.raises(DagsterEventLogInvalidForRun): storage.get_logs_for_run('foo') SqlEventLogStorageMetadata.create_all( create_engine(storage.conn_string_for_run_id('bar'))) with storage.connect('bar') as conn: # pylint: disable=protected-access event_insert = SqlEventLogStorageTable.insert().values( # pylint: disable=no-value-for-parameter run_id='bar', event='3', dagster_event_type=None, timestamp=None) conn.execute(event_insert) with pytest.raises(DagsterEventLogInvalidForRun): storage.get_logs_for_run('bar')
def store_event(self, event): '''Store an event corresponding to a pipeline run. Args: event (EventRecord): The event to store. ''' check.inst_param(event, 'event', EventRecord) dagster_event_type = None if event.is_dagster_event: dagster_event_type = event.dagster_event.event_type_value run_id = event.run_id with self.connect() as conn: # https://stackoverflow.com/a/54386260/324449 event_insert = SqlEventLogStorageTable.insert().values( # pylint: disable=no-value-for-parameter run_id=run_id, event=serialize_dagster_namedtuple(event), dagster_event_type=dagster_event_type, timestamp=datetime.datetime.fromtimestamp(event.timestamp), ) result_proxy = conn.execute( event_insert.returning(SqlEventLogStorageTable.c.run_id, SqlEventLogStorageTable.c.id)) res = result_proxy.fetchone() result_proxy.close() conn.execute( '''NOTIFY {channel}, %s; '''.format(channel=CHANNEL_NAME), (res[0] + '_' + str(res[1]), ), )