Skip to content

Commit

Permalink
Created a new method execution category named "BG_JOBS" to handle int…
Browse files Browse the repository at this point in the history
…ernal calls

BG_JOBS does not require session/auth/perm check and does not try to return anythingo
Moved sync_wf_cache from VIEW_URLS to BG_JOBS

rref #5357
#GH-64
  • Loading branch information
evrenesat committed Aug 29, 2016
1 parent 76ea16e commit c45e1a1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion zengine/models/workflow_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
6 changes: 5 additions & 1 deletion zengine/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -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',
Expand Down
6 changes: 3 additions & 3 deletions zengine/views/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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']
Expand All @@ -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
25 changes: 18 additions & 7 deletions zengine/wf_daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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'):
Expand Down

0 comments on commit c45e1a1

Please sign in to comment.