Skip to content

Commit

Permalink
Chained campaign chain type
Browse files Browse the repository at this point in the history
* Add default data list in database search

* Add chain_type to chained campaign

* Fix mistake: TaskType to TaskChain
  • Loading branch information
justinasr authored Aug 21, 2018
1 parent c5fbfc4 commit 3b7925f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
19 changes: 12 additions & 7 deletions mcm/couchdb_layer/mcm_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,8 @@ def full_text_search(self, index_name, query, page=0, limit=20, get_raw=False, i
__retries = 3
limit, skip = self.__pagify(int(page), limit=int(limit))
url = "_design/lucene/%s?q=%s" % (index_name, query)
for i in xrange(1, __retries+1):
data = {'rows': []}
for i in xrange(1, __retries + 1):
try:
options = {
'limit': limit,
Expand All @@ -549,16 +550,20 @@ def full_text_search(self, index_name, query, page=0, limit=20, get_raw=False, i
options['include_fields'] = include_fields
if sort != '':
options['sort'] = sort
data = self.db.FtiSearch(url, options=options, get_raw=get_raw) #we sort ascending by doc._id field
data = self.db.FtiSearch(url, options=options, get_raw=get_raw) # we sort ascending by doc._id field
break
except Exception as ex:
self.logger.info("lucene DB query: %s failed %s. retrying: %s out of: %s" % (
url, ex, i, __retries))
##if we are retrying we should wait little bit
self.logger.info("lucene DB query: %s failed %s. retrying: %s out of: %s" % (url,
ex,
i,
__retries))
# if we are retrying we should wait little bit
time.sleep(0.5)

if include_fields != '':
return [ elem["fields"] for elem in data['rows']]
return data if get_raw else [ elem["doc"] for elem in data['rows']]
return [elem["fields"] for elem in data['rows']]

return data if get_raw else [elem["doc"] for elem in data['rows']]

def raw_view_query(self, view_doc, view_name, options={}, cache=True):
sequence_id = "%s/%s" % (view_doc, view_name)
Expand Down
6 changes: 4 additions & 2 deletions mcm/json_layer/chained_campaign.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def __str__(self):
'flag': True
},
'history': [],
'valid': True
'valid': True,
'chain_type': 'TaskChain'
}

def __init__(self, json_input=None):
Expand Down Expand Up @@ -119,8 +120,9 @@ def generate_request(self, root_request_id):

# set values
creq.set_attribute('pwg', pwg)
creq.set_attribute('member_of_campaign', self.get_attribute('prepid'))
creq.set_attribute('member_of_campaign', self.get_attribute('prepid'))
creq.set_attribute('action_parameters', self.get_attribute('action_parameters'))
creq.set_attribute('chain_type', self.get_attribute('chain_type'))
# By default flag should be true
creq.get_attribute('action_parameters')['flag'] = True
if not creq.get_attribute('prepid'):
Expand Down
9 changes: 9 additions & 0 deletions mcm/rest_api/ChainedRequestActions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from tools.user_management import access_rights
from flask_restful import reqparse
from tools.locker import locker
from ChainedRequestPrepId import ChainedRequestPrepId


class CreateChainedRequest(RESTResource):
Expand Down Expand Up @@ -51,6 +52,14 @@ def import_request(self, data):
if not req.get_attribute('prepid'):
self.logger.error('prepid returned was None')
raise ValueError('Prepid returned was None')

if 'chain_type' in json_input:
chain_type = json_input['chain_type']
else:
ccdb = database('chained_campaigns')
chain_type = ccdb.get(json_input['member_of_campaign']).get('chain_type', 'TaskChain')

req.set_attribute('chain_type', chain_type)
self.logger.info('Created new chained_request %s' % cr_id)
# update history with the submission details
req.update_history({'action': 'created'})
Expand Down

0 comments on commit 3b7925f

Please sign in to comment.