diff --git a/zengine/models/workflow_manager.py b/zengine/models/workflow_manager.py index bdab5e6a..111d86cc 100644 --- a/zengine/models/workflow_manager.py +++ b/zengine/models/workflow_manager.py @@ -356,5 +356,5 @@ def save(self, wf_state): self.wf_state['role_id'] = self.current.role_id self.set(self.wf_state) if self.wf_state['name'] not in settings.EPHEMERAL_WORKFLOWS: - self.publish(view='_zops_sync_wf_cache', + self.publish(job='sync_wf_cache', token=self.db_key) diff --git a/zengine/settings.py b/zengine/settings.py index eede3e95..8ef5bec7 100644 --- a/zengine/settings.py +++ b/zengine/settings.py @@ -115,6 +115,11 @@ 'session.path': '/', } +BG_JOBS = { + 'sync_wf_cache': 'zengine.views.system.sync_wf_cache', +} + + #: View URL list for non-workflow views. #: #: ('URI template', 'python path to view method/class'), @@ -123,7 +128,6 @@ 'sessid_to_userid': 'zengine.views.system.sessid_to_userid', 'mark_offline_user': 'zengine.views.system.mark_offline_user', 'ping': 'zengine.views.dev_utils.Ping', - '_zops_sync_wf_cache': 'zengine.views.system.sync_wf_cache', '_zops_get_invites': 'zengine.views.system.get_invites', '_zops_create_message': 'zengine.messaging.views.create_message', '_zops_show_channel': 'zengine.messaging.views.show_channel', diff --git a/zengine/views/system.py b/zengine/views/system.py index 32f99bdc..9a7f4b37 100644 --- a/zengine/views/system.py +++ b/zengine/views/system.py @@ -8,6 +8,7 @@ # (GPLv3). See LICENSE.txt for details. import six from pyoko.exceptions import ObjectDoesNotExist +from zengine.models import BPMNWorkflow from zengine.models import WFCache from zengine.models import WFInstance, TaskInvitation @@ -45,8 +46,9 @@ def sync_wf_cache(current): try: wfi = WFInstance.objects.get(key=current.input['token']) except ObjectDoesNotExist: - # just for backwards compatibility + # wf's that not started from a task invitation wfi = WFInstance(key=current.input['token']) + wfi.wf = BPMNWorkflow.objects.get(name=wf_state['name']) wfi.step = wf_state['step'] wfi.name = wf_state['name'] wfi.pool = wf_state['pool'] @@ -60,5 +62,3 @@ def sync_wf_cache(current): else: pass # if cache already cleared, we have nothing to sync - # -1 means do not return anything to client - current.output = -1 diff --git a/zengine/wf_daemon.py b/zengine/wf_daemon.py index c45970e6..67e320e5 100755 --- a/zengine/wf_daemon.py +++ b/zengine/wf_daemon.py @@ -100,7 +100,20 @@ def _handle_ping_pong(self, data, session): msg.update(LOGIN_REQUIRED_MESSAGE) return msg + def _handle_job(self, session, data, headers): + self.current = Current(session=session, input=data) + self.current.headers = headers + # import method + method = get_object_from_path(settings.BG_JOBS[data['job']]) + # call view with current object + method(self.current) + + def _handle_view(self, session, data, headers): + # create Current object + self.current = Current(session=session, input=data) + self.current.headers = headers + # handle ping/pong/session expiration if data['view'] == 'ping': return self._handle_ping_pong(data, session) @@ -159,15 +172,13 @@ def handle_message(self, ch, method, properties, body): if 'wf' in data: output = self._handle_workflow(session, data, headers) - else: - # create Current object - self.current = Current(session=session, input=data) - self.current.headers = headers + elif 'job' in data: + self._handle_job(session, data, headers) + return + else: output = self._handle_view(session, data, headers) - if output == -1: - # -1 means we don't want to return anything to client - return + except HTTPError as e: import sys if hasattr(sys, '_called_from_test'):