[service] drop the asynchronous execution possibility
Call_service was able of both sync and sync execution making the API confusing.
There is not user of the async case. We drop the async argument in favor of
synchronous execution only.
This makes call_service the official API to call server side code from the
client side. This is a remplacement for the usual monkey patching of the repo
object.
The zmq notification bus is a solid alternative for codes that needs to start an
async execution.
--- a/dbapi.py Mon Jun 24 12:00:03 2013 +0200
+++ b/dbapi.py Mon Jun 24 11:59:45 2013 +0200
@@ -368,8 +368,8 @@
# server-side service call #################################################
- def call_service(self, regid, async=False, **kwargs):
- return self.cnx.call_service(regid, async, **kwargs)
+ def call_service(self, regid, **kwargs):
+ return self.cnx.call_service(regid, **kwargs)
# entities cache management ###############################################
@@ -596,8 +596,8 @@
# server-side service call #################################################
@check_not_closed
- def call_service(self, regid, async=False, **kwargs):
- return self._repo.call_service(self.sessionid, regid, async, **kwargs)
+ def call_service(self, regid, **kwargs):
+ return self._repo.call_service(self.sessionid, regid, **kwargs)
# connection initialization methods ########################################
--- a/doc/4.0.rst Mon Jun 24 12:00:03 2013 +0200
+++ b/doc/4.0.rst Mon Jun 24 11:59:45 2013 +0200
@@ -11,6 +11,10 @@
* ``SessionManager`` and ``AuthenticationManager`` now take a repo object at
initialization time instead of a vreg.
+* The ``async`` argument of ``_cw.call_service`` have been dropped. All call are
+ now synchronous. The zmq notification bus looks like a good replacement for
+ most async usecase.
+
Deprecated Code Drops
----------------------
--- a/server/repository.py Mon Jun 24 12:00:03 2013 +0200
+++ b/server/repository.py Mon Jun 24 11:59:45 2013 +0200
@@ -890,33 +890,22 @@
del self._sessions[sessionid]
self.info('closed session %s for user %s', sessionid, session.user.login)
- def call_service(self, sessionid, regid, async, **kwargs):
+ def call_service(self, sessionid, regid, **kwargs):
"""
See :class:`cubicweb.dbapi.Connection.call_service`
and :class:`cubicweb.server.Service`
"""
session = self._get_session(sessionid)
- return self._call_service_with_session(session, regid, async, **kwargs)
+ return self._call_service_with_session(session, regid, **kwargs)
- def _call_service_with_session(self, session, regid, async, **kwargs):
- if async:
- self.info('calling service %s asynchronously', regid)
- def task():
- session.set_cnxset()
- try:
- service = session.vreg['services'].select(regid, session, **kwargs)
- return service.call(**kwargs)
- finally:
- session.rollback() # free cnxset
- self.threaded_task(task)
- else:
- self.info('calling service %s synchronously', regid)
- session.set_cnxset()
- try:
- service = session.vreg['services'].select(regid, session, **kwargs)
- return service.call(**kwargs)
- finally:
- session.free_cnxset()
+ def _call_service_with_session(self, session, regid, **kwargs):
+ self.info('calling service %s synchronously', regid)
+ session.set_cnxset()
+ try:
+ service = session.vreg['services'].select(regid, session, **kwargs)
+ return service.call(**kwargs)
+ finally:
+ session.free_cnxset()
def user_info(self, sessionid, props=None):
"""this method should be used by client to:
--- a/server/session.py Mon Jun 24 12:00:03 2013 +0200
+++ b/server/session.py Mon Jun 24 11:59:45 2013 +0200
@@ -1168,8 +1168,8 @@
# server-side service call #################################################
- def call_service(self, regid, async=False, **kwargs):
- return self.repo._call_service_with_session(self, regid, async,
+ def call_service(self, regid, **kwargs):
+ return self.repo._call_service_with_session(self, regid,
**kwargs)