Could you advise what would be the best approach for the following problem.
I have Flask-Celery task. Task consists of two functions (both are run
in the same one Celery task): A and B. Function A calculates values
which are then used by B function. Values are stored in DB (via
SQLAlchemy). The problem is that, somehow, values from A are commited
too slow (?), so function B has nothing to calc (whole task has to be
called once again to get results from function B).
I use below pattern:
New values inside function A are commited this way:
/try://
//
// inserting_session.add(new_value)//
//
// inserting_session.commit()//
//
//except Exception as e://
//
// inserting_session.rollback()//
//
//and after all values are worked out://
//
//inserting_session.close()/
Where:
/class SQLSession(object)://
//
// sql_engine = None//
//
// @staticmethod//
// def sql_session()://
//
// if SQLSession.sql_engine is None://
//
// # create engine//
//
// SQLSession.sql_engine = create_engine([...]),//
// pool_recycle=30//
// )//
//
// # create a configured "Session" class//
//
// insering_session_maker =
sessionmaker(bind=SQLSession.sql_engine)//
//
// # scope session//
//
// inserting_session = scoped_session(insering_session_maker)//
//
// # create a Session//
//
// inserting_session_scoped = inserting_session()//
//
// return inserting_session_scoped//
//
//
//inserting_session = SQLSession.sql_session()/
It works when instead of
/
//inserting_session.close()/
close_all() is called:
/inserting_session.close()/
But it probably is not the best solution.
The question is - how to deal with this issue?
Cheers!
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.