Univention Bugzilla – Bug 30258
UMC-Server: Add decorator for simple functions with background tasks
Last modified: 2019-02-27 18:05:52 CET
Created attachment 5034 [details] Proof of concept for a threading decorator At the moment, adding a "non-blocking" function to a module is quite painful. It is often done this way: def nonblock(self, request): var1 = request.options.get('var1') self.finished(request.id, var1 * 2) def _thread(var): do_some_expensive_stuff(var) def _finished(thread, result): if isinstance(result, BaseException): MODULE.warn('Exception during expensive: %s' % (str(result)) thread = notifier.threads.Simple('nonblock', notifier.Callback(_thread, var1), _finished) thread.run() In UCS 3.1 we have added a decorator for simple tasks (@simple_response), but it is limited when it comes to background tasks that should not block the whole module. We should extend its function to be able to spawn a thread after sending a response easily. Idea: @simple_response def nonblock(self, var1): yield var1 * 2 do_some_expensive_stuff(var1) Proof of concept attached (does not work very well together with @log at the moment). Used App Center for demonstration. The function could be helpful in a couple of modules (requiring nonblocking actions was the #1 show stopper to use @simple_response at a larger scale). I have been working on one third-party module and this could have used it, too.
This issue has been filled against UCS 4.1. The maintenance with bug and security fixes for UCS 4.1 has ended on 5st of April 2018. Customers still on UCS 4.1 are encouraged to update to UCS 4.3. Please contact your partner or Univention for any questions. If this issue still occurs in newer UCS versions, please use "Clone this bug" or simply reopen the issue. In this case please provide detailed information on how this issue is affecting you.