private async Task <bool> TryPush(Message msg) { using (var session = sessionFactory.OpenStatelessSession()) { var tx = session.BeginTransaction(); try { await PublishMessage(msg); session .CreateQuery("delete Message where id=:id") .SetParameter("id", msg.Id) .ExecuteUpdate(); tx.Commit(); logger.LogSuccessPush(); return(true); } catch (Exception e) { logger.LogFailedPush(e); tx?.Rollback(); return(false); } } }
private bool TryInTx(Action <IStatelessSession> action) { using (var session = sessionFactory.OpenStatelessSession()) { var tx = session.BeginTransaction(); try { action(session); tx.Commit(); logger.LogSuccessPush(); return(true); } catch (Exception e) { logger.LogFailedPush(e); tx?.Rollback(); return(false); } } }